11 #define NUM_MALLOC (10000)
12 #define SIZE_MALLOC (10000)
13 #define POOL_SIZE (NUM_MALLOC*SIZE_MALLOC)
33 gettimeofday (&tv
, &tz
);
34 return ((tv
.tv_usec
/ 1000000.0) + (1.0 * tv
.tv_sec
));
49 update (int print
, const char *n
, double s
, double e
, minmax
* data
)
58 data
->sumquad
+= d
* d
;
59 mean
= data
->sum
/ data
->n
;
60 sigma
= sqrt ((data
->sumquad
- ((data
->sum
* data
->sum
) / data
->n
)) /
70 mean
= data
->sum
/ data
->n
;
71 sigma
= sqrt ((data
->sumquad
- ((data
->sum
* data
->sum
) / data
->n
)) /
75 printf ("%s min=%.9f, max=%.9f, mean=%.9f, sigma=%.9f\n",
76 n
? n
: data
->name
, data
->min
, data
->max
, mean
, sigma
);
84 static char pool
[POOL_SIZE
];
93 double s
, first
, last_h
;
95 minmax maldata
, raldata
, freedata
;
97 free_mem
= init_memory_pool (POOL_SIZE
, pool
);
98 printf ("Total free memory = %d\n", free_mem
);
102 m
= (void **) tlsf_malloc (NUM_MALLOC
* sizeof (void *));
103 for (i
= 0; i
< NUM_MALLOC
; i
++) {
106 first
= last_h
= getcurtime ();
107 for (i
= 0; i
< NUM_MALLOC
; i
++) {
108 t
= (size_t) (1 + drand48 () * SIZE_MALLOC
);
109 m
[i
] = tlsf_calloc (t
, 1);
110 if (((unsigned long) m
[i
] & (sizeof(void *) * 2 - 1)) != 0) {
111 fprintf(stderr
,"Alignment error %p\n", m
[i
]);
114 memset (m
[i
], -1, t
);
117 for (j
= 0; j
< 1000; j
++) {
118 for (i
= 0; i
< NUM_MALLOC
; i
++) {
120 t
= (size_t) (1 + drand48 () * SIZE_MALLOC
);
122 m
[i
] = tlsf_realloc (m
[i
], t
);
123 update (0, "realloc", s
, getcurtime (), &raldata
);
124 if (((unsigned long) m
[i
] & (sizeof(void *) * 2 - 1)) != 0) {
125 fprintf(stderr
,"Alignment error %p\n", m
[i
]);
128 memset (m
[i
], -1, t
);
134 update (0, "free ", s
, getcurtime (), &freedata
);
136 t
= (size_t) (1 + drand48 () * SIZE_MALLOC
);
138 m
[i
] = tlsf_malloc (t
);
139 update (0, "malloc ", s
, getcurtime (), &maldata
);
140 if (((unsigned long) m
[i
] & (sizeof(void *) * 2 - 1)) != 0) {
141 fprintf(stderr
,"Alignment error %p\n", m
[i
]);
144 memset (m
[i
], -1, t
);
149 if ((s
- last_h
) > 10) {
151 printf ("Count = %d %f\n",
152 n
* NUM_MALLOC
, last_h
- first
);
153 update (1, NULL
, 0.0, getcurtime (), &maldata
);
154 update (1, NULL
, 0.0, getcurtime (), &raldata
);
155 update (1, NULL
, 0.0, getcurtime (), &freedata
);
158 for (i
= 0; i
< NUM_MALLOC
; i
++) {