Annotation of libelwix/example/test_mem_bench.c, revision 1.1.2.1
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);
! 30: for (i = 0; i < n; i++)
! 31: a[i] = malloc(BUFSIZ);
! 32: for (i = 0; i < n; i++)
! 33: free(a[i]);
! 34: clock_gettime(CLOCK_MONOTONIC, &ets);
! 35: perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
! 36: printf("Performance time %.6f for alloc memory and free\n", perf);
! 37:
! 38: clock_gettime(CLOCK_MONOTONIC, &bts);
! 39: for (i = 0; i < n; i++) {
! 40: p = e_malloc(BUFSIZ);
! 41: e_free(p);
! 42: }
! 43: clock_gettime(CLOCK_MONOTONIC, &ets);
! 44: perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
! 45: printf("ELWIX Performance time %.6f for alloc memory + free\n", perf);
! 46:
! 47: clock_gettime(CLOCK_MONOTONIC, &bts);
! 48: for (i = 0; i < n; i++) {
! 49: a[i] = e_malloc(BUFSIZ);
! 50: if (!a[i]) {
! 51: printf("Error:: can't allocate on position %d\n", i);
! 52: break;
! 53: }
! 54: }
! 55: for (--i; i > -1; i--)
! 56: e_free(a[i]);
! 57: clock_gettime(CLOCK_MONOTONIC, &ets);
! 58: perf = ets.tv_sec - bts.tv_sec + ((ets.tv_nsec - bts.tv_nsec) / 1e9);
! 59: printf("ELWIX Performance time %.6f for alloc memory and free\n", perf);
! 60: free(a);
! 61: return 0;
! 62: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>