head 1.9; access; symbols; locks; strict; comment @ * @; 1.9 date 2008.04.12.00.09.32; author wessels; state Exp; branches; next 1.8; 1.8 date 2006.12.12.08.58.18; author wessels; state Exp; branches; next 1.7; 1.7 date 2006.12.12.08.46.40; author wessels; state Exp; branches; next 1.6; 1.6 date 2006.12.12.08.41.32; author wessels; state Exp; branches; next 1.5; 1.5 date 2006.12.12.08.30.03; author wessels; state Exp; branches; next 1.4; 1.4 date 2006.12.12.08.23.54; author wessels; state Exp; branches; next 1.3; 1.3 date 2006.12.12.08.04.49; author wessels; state Exp; branches; next 1.2; 1.2 date 99.08.19.22.29.18; author wessels; state Exp; branches; next 1.1; 1.1 date 99.08.19.22.15.41; author wessels; state Exp; branches; next ; desc @@ 1.9 log @use uint64_t instead of int for various variables so we can allocate more than 4GB @ text @/* * $Id: test_memory.c,v 1.8 2006/12/12 08:58:18 wessels Exp $ * * Copyright 2006 Duane Wessels. */ #include #include #include #include #include #include #include #define LONGS_PER_CHUNK 1024 void progress(uint64_t, uint64_t); void allocate(uint64_t mb); void test(uint64_t); uint64_t pos = 0; time_t start; long **chunks; uint64_t maxi; int main(int argc, char *argv[]) { uint64_t MB; uint64_t pass = 0; start = time(NULL); setbuf(stdout, NULL); setbuf(stderr, NULL); if (argc != 2) { fprintf(stderr, "usage: %s mbytes\n", argv[0]); return 1; } MB = atoi(argv[1]); assert(MB); allocate(MB); while (1) test(pass++); return 0; } void allocate(uint64_t MB) { uint64_t chunksize = LONGS_PER_CHUNK * sizeof(long); uint64_t nchunks = (MB << 20) / chunksize; uint64_t i = 0; fprintf(stderr, "allocating %"PRIu64" total bytes in %"PRIu64" chunks of %"PRIu64" bytes each\n", nchunks * chunksize, nchunks, chunksize); chunks = malloc(nchunks * sizeof(long *)); assert(chunks); printf("allocate: "); while (i < nchunks) { uint64_t j; *(chunks + i) = malloc(chunksize); if (*(chunks + i) == NULL) { perror("malloc"); break; } srandom(i + start); for (j = 0; j < LONGS_PER_CHUNK; j++) *(*(chunks + i) + j) = random(); progress(i, nchunks); maxi = ++i; } putc('.', stdout); putc('\n', stdout); } void test(uint64_t pass) { uint64_t i; printf("pass %0"PRIu64": ", pass); for (i = 0; i < maxi; i++) { uint64_t j; srandom(i + start); for (j = 0; j < LONGS_PER_CHUNK; j++) { long e = random(); if (*(*(chunks + i) + j) != e) { fprintf(stderr, "\nERROR got %lx, expect %lx, i=%"PRIu64", j=%"PRIu64"\n", *(*(chunks + i) + j), e, i, j); } } progress(i, maxi); } putc('.', stdout); putc('\n', stdout); } void progress(uint64_t i, uint64_t max) { uint64_t x; static int swirl[4] = {'-', '\\', '|', '/'}; if ((i & 0xFF) != 0) return; putc(swirl[(i >> 8) % 4], stdout); putc('\b', stdout); x = 68 * i / max; if (x == pos) return; if (x < pos) { pos = 0; return; } putc('.', stdout); pos = x; } @ 1.8 log @need to initialize some counters @ text @d2 1 a2 1 * $Id: test_memory.c,v 1.7 2006/12/12 08:46:40 wessels Exp wessels $ d13 1 d17 3 a19 3 void progress(int, int); void allocate(int mb); void test(int); d21 1 a21 1 int pos = 0; d24 1 a24 1 int maxi; d29 2 a30 2 int MB; int pass = 0; d47 1 a47 1 allocate(int MB) d49 4 a52 4 int chunksize = LONGS_PER_CHUNK * sizeof(long); int nchunks = (MB << 20) / chunksize; int i = 0; fprintf(stderr, "allocating %d total bytes in %d chunks of %d bytes each\n", d58 1 a58 1 int j; d75 1 a75 1 test(int pass) d77 2 a78 2 int i; printf("pass %3d: ", pass); d80 1 a80 1 int j; d85 1 a85 1 fprintf(stderr, "\nERROR got %lx, expect %lx, i=%d, j=%d\n", d96 1 a96 1 progress(int i, int max) d98 1 a98 1 int x; @ 1.7 log @formatting @ text @d2 1 a2 1 * $Id: test_memory.c,v 1.6 2006/12/12 08:41:32 wessels Exp wessels $ d50 1 a50 2 int i; int j; d57 1 a76 2 int j; long e; d79 1 d82 1 a82 1 e = random(); @ 1.6 log @use more functions @ text @d1 6 a6 1 static char rcsid[] = "$Id: test_memory.c,v 1.5 2006/12/12 08:30:03 wessels Exp wessels $"; d40 1 a40 1 while (1) { a41 1 } d85 2 a86 1 fprintf(stderr, "\nERROR got %lx, expect %lx, i=%d, j=%d\n", *(*(chunks + i) + j), e, i, j); d96 1 a96 1 progress(int i, int nchunks) a101 1 x = 68 * i / nchunks; d104 1 @ 1.5 log @*** empty log message *** @ text @d1 1 a1 1 static char rcsid[] = "$Id: test_memory.c,v 1.4 2006/12/12 08:23:54 wessels Exp wessels $"; a10 1 int pos = 0; d13 27 a39 1 void test(void); d44 4 a47 1 nchunks = (MB << 20) / chunksize; d50 2 a51 2 foo = malloc(nchunks * sizeof(long *)); assert(foo); d54 2 a55 2 *(foo + i) = malloc(chunksize); if (*(foo + i) == NULL) { d61 1 a61 2 *(*(foo + i) + j) = random(); maxi = i++; d63 1 d69 2 a70 2 int main(int argc, char *argv[]) d72 2 a73 1 long **foo; d75 7 a81 26 int i = 0; int maxi; int j; int MB; int chunksize = LONGS_PER_CHUNK * sizeof(long); int nchunks; int pass = 0; time_t start = time(NULL); setbuf(stdout, NULL); setbuf(stderr, NULL); if (argc != 2) { fprintf(stderr, "usage: %s mbytes\n", argv[0]); return 1; } MB = atoi(argv[1]); assert(MB); while (1) { printf("pass %3d: ", pass++); for (i = 0; i < maxi; i++) { srandom(i + start); for (j = 0; j < LONGS_PER_CHUNK; j++) { e = random(); if (*(*(foo + i) + j) != e) { fprintf(stderr, "\nERROR got %lx, expect %lx, i=%d, j=%d\n", *(*(foo + i) + j), e, i, j); } a82 1 progress(i, maxi); d84 1 a84 2 putc('.', stdout); putc('\n', stdout); d86 2 a87 1 return 0; a89 1 d94 1 a94 1 static int swirl[4] = { '-', '\\', '|', '/' }; d98 1 a98 1 putc(swirl[(i>>8)%4], stdout); @ 1.4 log @change swirl direction @ text @d1 1 a1 1 static char rcsid[] = "$Id: test_memory.c,v 1.3 2006/12/12 08:04:49 wessels Exp wessels $"; d13 27 d62 1 a62 20 nchunks = (MB << 20) / chunksize; fprintf(stderr, "allocating %d total bytes in %d chunks of %d bytes each\n", nchunks * chunksize, nchunks, chunksize); foo = malloc(nchunks * sizeof(long *)); assert(foo); printf("allocate: "); while (i < nchunks) { *(foo + i) = malloc(chunksize); if (*(foo + i) == NULL) { perror("malloc"); break; } srandom(i + start); for (j = 0; j < LONGS_PER_CHUNK; j++) *(*(foo + i) + j) = random(); maxi = i++; progress(i, nchunks); } putc('.', stdout); putc('\n', stdout); @ 1.3 log @add some swirl @ text @d1 1 a1 1 static char rcsid[] = "$Id: test_memory.c,v 1.2 1999/08/19 22:29:18 wessels Exp $"; d78 1 a78 1 static int swirl[4] = { '-', '/', '|', '\\' }; @ 1.2 log @bugs, command line args @ text @d1 1 a1 1 static char rcsid[] = "$Id: test_memory.c,v 1.3 1997/07/07 23:51:39 wessels Exp $"; d11 3 d51 1 a51 2 if ((i & 0xFF) == 0) putc('.', stdout); d53 1 d65 1 a65 2 if ((i & 0xFF) == 0) putc('.', stdout); d67 1 d71 21 @ 1.1 log @Initial revision @ text @d7 6 a12 1 int main(int argc, char *argv[]) d14 1 a14 1 long **foo = malloc(32768 * sizeof(long *)); d19 4 d26 14 a39 2 while (i < 32768) { *(foo + i) = malloc(1024 * sizeof(long)); d45 1 a45 1 for (j = 0; j < 1024; j++) d48 2 d51 1 d53 1 d56 1 a56 1 for (j = 0; j < 1024; j++) { d65 1 @