Annotation of libelwix/example/test_mem_bench.c, revision 1.1.2.2
1.1.2.1 misho 1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <time.h>
4: #include <elwix.h>
5:
6:
7: int
8: main(int argc, char **argv)
9: {
10: struct timespec bts, ets;
11: double perf;
12: register int i;
13: void *p, **a;
14: int n = argc > 1 ? atoi(argv[1]) : 1;
15:
16: a = malloc(sizeof(void*) * n);
17: if (!a)
18: return 1;
19:
20: clock_gettime(CLOCK_MONOTONIC, &bts);
21: for (i = 0; i < n; i++) {
22: p = malloc(BUFSIZ);
23: free(p);
24: }
25: clock_gettime(CLOCK_MONOTONIC, &ets);
26: perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
27: printf("Performance time %.6f for alloc memory + free\n", perf);
28:
29: clock_gettime(CLOCK_MONOTONIC, &bts);
1.1.2.2 ! misho 30: for (i = 0; i < n; i++) {
1.1.2.1 misho 31: a[i] = malloc(BUFSIZ);
1.1.2.2 ! misho 32: if (!a[i]) {
! 33: printf("Error:: can't allocate on position %d\n", i);
! 34: break;
! 35: }
! 36: }
! 37: for (--i; i > -1; i--)
1.1.2.1 misho 38: free(a[i]);
39: clock_gettime(CLOCK_MONOTONIC, &ets);
40: perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
41: printf("Performance time %.6f for alloc memory and free\n", perf);
42:
43: clock_gettime(CLOCK_MONOTONIC, &bts);
44: for (i = 0; i < n; i++) {
45: p = e_malloc(BUFSIZ);
46: e_free(p);
47: }
48: clock_gettime(CLOCK_MONOTONIC, &ets);
49: perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
50: printf("ELWIX Performance time %.6f for alloc memory + free\n", perf);
51:
52: clock_gettime(CLOCK_MONOTONIC, &bts);
53: for (i = 0; i < n; i++) {
54: a[i] = e_malloc(BUFSIZ);
55: if (!a[i]) {
56: printf("Error:: can't allocate on position %d\n", i);
57: break;
58: }
59: }
60: for (--i; i > -1; i--)
61: e_free(a[i]);
62: clock_gettime(CLOCK_MONOTONIC, &ets);
63: perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
64: printf("ELWIX Performance time %.6f for alloc memory and free\n", perf);
65: free(a);
66: return 0;
67: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>