usermode/library/malloc-hoard-old/benchmarks/testmymalloc/testmymalloc.cpp

00001 
00002 //
00003 // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
00004 //        for Shared-Memory Multiprocessors
00005 // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
00006 //
00007 // Copyright (c) 1998-2000, The University of Texas at Austin.
00008 //
00009 // This library is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU Library General Public License as
00011 // published by the Free Software Foundation, http://www.fsf.org.
00012 //
00013 // This library is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00019 
00020 #include <assert.h>
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 
00024 #include "timer.h"
00025 
00026 class Foo {
00027 public:
00028   Foo (void)
00029     : x (143.0)
00030     {}
00031 
00032   double x;
00033 };
00034 
00035 
00036 int main (int argc, char * argv[])
00037 {
00038   int iterations;
00039   int size;
00040 
00041   if (argc > 2) {
00042     iterations = atoi(argv[1]);
00043     size = atoi(argv[2]);
00044   } else {
00045     fprintf (stderr, "Usage: %s iterations size\n", argv[0]);
00046     exit(1);
00047   }
00048 
00049   Timer t1, t2;
00050 
00051   long int i, j;
00052   Foo ** a;
00053   a = new Foo * [iterations];
00054 
00055   for (int n = 0; n < 1; n++) {
00056     t1.start ();
00057     for (i = 0; i < iterations; i++) {
00058       a[i] = new Foo[size];
00059     }
00060     t1.stop ();
00061     
00062     t2.start ();
00063     for (j = iterations - 1; j >= 0; j--) {
00064       delete [] a[j];
00065     }
00066     t2.stop ();
00067   }
00068 
00069   delete [] a;
00070 
00071   printf( "Alloc: %f\n", (double) t1);
00072   printf("free: %f\n", (double) t2);
00073   printf("total: %f\n", (double) t1 + (double) t2);
00074 
00075   return 0;
00076 }

Generated on Sat Apr 23 11:43:35 2011 for Mnemosyne by  doxygen 1.4.7