#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <elwix.h>
int
main(int argc, char **argv)
{
struct timespec bts, ets;
double perf;
register int i;
void *p, **a;
int n = argc > 1 ? atoi(argv[1]) : 1;
a = malloc(sizeof(void*) * n);
if (!a)
return 1;
clock_gettime(CLOCK_MONOTONIC, &bts);
for (i = 0; i < n; i++) {
p = malloc(BUFSIZ);
free(p);
}
clock_gettime(CLOCK_MONOTONIC, &ets);
perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
printf("Performance time %.6f for alloc memory + free\n", perf);
clock_gettime(CLOCK_MONOTONIC, &bts);
for (i = 0; i < n; i++) {
a[i] = malloc(BUFSIZ);
if (!a[i]) {
printf("Error:: can't allocate on position %d\n", i);
break;
}
}
for (--i; i > -1; i--)
free(a[i]);
clock_gettime(CLOCK_MONOTONIC, &ets);
perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
printf("Performance time %.6f for alloc memory and free\n", perf);
clock_gettime(CLOCK_MONOTONIC, &bts);
for (i = 0; i < n; i++) {
p = e_malloc(BUFSIZ);
e_free(p);
}
clock_gettime(CLOCK_MONOTONIC, &ets);
perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
printf("ELWIX Performance time %.6f for alloc memory + free\n", perf);
clock_gettime(CLOCK_MONOTONIC, &bts);
for (i = 0; i < n; i++) {
a[i] = e_malloc(BUFSIZ);
if (!a[i]) {
printf("Error:: can't allocate on position %d\n", i);
break;
}
}
for (--i; i > -1; i--)
e_free(a[i]);
clock_gettime(CLOCK_MONOTONIC, &ets);
perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
printf("ELWIX Performance time %.6f for alloc memory and free\n", perf);
free(a);
return 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>