another example
[tridge/junkcode.git] / malloc_speed.c
1 #include <stdlib.h>
2 #include <stdio.h>
3
4 int main(int argc, char *argv[])
5 {
6         int i;
7         time_t t, t2;
8         int count = atoi(argv[1]);
9         int size = atoi(argv[2]);
10
11         t = time(NULL);
12
13         for (i=0;i<count; i++) {
14                 char *p;
15                 p = malloc(size);
16                 if (!p) {
17                         printf("malloc failed!\n");
18                         exit(1);
19                 }
20                 free(p);
21         }
22
23         t2 = time(NULL);
24         
25         printf("%g ops/sec\n", (2.0*i) / (t2-t));
26         return 0;
27 }