Leopold Toetsch wrote:
> Appended is a test program
Arg, damned Mozilla, shows attachment and doesn't include it
/* test program for malloc */
/* run program with
* cc -o chkm -Wall chkm.c -O3 && ./chkm
* cc -o chkm -Wall chkm.c malloc.c -O3 && ./chkm
*
* the timing macro needs adjustment for !i386
*/
#include <stdio.h>
#include <malloc.h>
#include <stdarg.h>
#define rdtscl(low) \
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
int
PIO_eprintf(void *i, const char *s, ...) {
va_list args;
int ret;
va_start(args, s);
ret=vfprintf(stderr, s, args);
va_end(args);
return ret;
}
int main(int argc, char *argv[])
{
long a,b,c,d,e,f,g;
char *buf, *buf2;
size_t size = 1;
int i, j, u;
printf(" size 1.mal 2.mal 3.mal memset clean\n");
for (i = 0; i < 24; i++) {
rdtscl(a);
buf = malloc(size);
rdtscl(b);
buf2 = malloc(size);
rdtscl(c);
for (j = 0; j < i; j++)
buf[j] = j & 0xff;
free(buf);
rdtscl(d);
buf = malloc(size);
rdtscl(e);
u = 0;
for (j = 0; j < i; j++)
if (buf[j] != 0) {
u = 1;
break;
}
f = g = 0;
if (u) {
rdtscl(f);
memset(buf, 0, size);
rdtscl(g);
}
printf("%8d %8lu %8lu %8lu %8ld %s\n",
size, b-a, c-b, e-d, g-f, u ? "**": "0");
size <<= 1;
}
return 0;
}
/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
*/