Changeset 433 for pjproject/trunk/pjlib/src/pjlib-test/pool_perf.c
- Timestamp:
- May 10, 2006 7:24:40 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/pool_perf.c
r65 r433 33 33 #define COUNT 1024 34 34 static unsigned sizes[COUNT]; 35 static char *p[COUNT]; 35 36 #define MIN_SIZE 4 36 37 #define MAX_SIZE 512 37 38 static unsigned total_size; 39 38 40 39 41 static int pool_test_pool() … … 46 48 for (i=0; i<COUNT; ++i) { 47 49 char *p; 48 if ( (p=(char*)pj_pool_alloc(pool, sizes[i])) == NULL) 50 if ( (p=(char*)pj_pool_alloc(pool, sizes[i])) == NULL) { 51 PJ_LOG(3,(THIS_FILE," error: pool failed to allocate %d bytes", 52 sizes[i])); 53 pj_pool_release(pool); 49 54 return -1; 55 } 50 56 *p = '\0'; 51 57 } … … 57 63 static int pool_test_malloc_free() 58 64 { 59 char *p[COUNT]; 60 int i; 65 int i; /* must be signed */ 61 66 62 67 for (i=0; i<COUNT; ++i) { 63 68 p[i] = (char*)malloc(sizes[i]); 64 69 if (!p[i]) { 65 // Don't care for memory leak in this test 70 PJ_LOG(3,(THIS_FILE," error: malloc failed to allocate %d bytes", 71 sizes[i])); 72 --i; 73 while (i >= 0) 74 free(p[i]), --i; 66 75 return -1; 67 76 } … … 83 92 pj_uint32_t best, worst; 84 93 85 / / Initialize sizes.94 /* Initialize size of chunks to allocate in for the test. */ 86 95 for (i=0; i<COUNT; ++i) { 87 sizes[i] = MIN_SIZE + pj_rand() % MAX_SIZE;96 sizes[i] = MIN_SIZE + (pj_rand() % MAX_SIZE); 88 97 total_size += sizes[i]; 89 98 } 90 99 100 /* Add some more for pool admin area */ 101 total_size += 512; 102 91 103 PJ_LOG(3, (THIS_FILE, "Benchmarking pool..")); 92 104 93 / / Warmup105 /* Warmup */ 94 106 pool_test_pool(); 95 107 pool_test_malloc_free(); … … 118 130 } 119 131 120 PJ_LOG(4, (THIS_FILE, "..LOOP count: %u",LOOP));121 PJ_LOG(4, (THIS_FILE, "..number of alloc/dealloc per loop: %u",COUNT));122 PJ_LOG(4, (THIS_FILE, "..pool allocation/deallocation time: %u",pool_time));123 PJ_LOG(4, (THIS_FILE, "..malloc/free time: %u",malloc_time));124 PJ_LOG(4, (THIS_FILE, "..pool again, second invocation: %u",pool_time2));132 PJ_LOG(4,(THIS_FILE,"..LOOP count: %u",LOOP)); 133 PJ_LOG(4,(THIS_FILE,"..number of alloc/dealloc per loop: %u",COUNT)); 134 PJ_LOG(4,(THIS_FILE,"..pool allocation/deallocation time: %u",pool_time)); 135 PJ_LOG(4,(THIS_FILE,"..malloc/free time: %u",malloc_time)); 136 PJ_LOG(4,(THIS_FILE,"..pool again, second invocation: %u",pool_time2)); 125 137 126 138 if (pool_time2==0) pool_time2=1; … … 130 142 best = pool_time2, worst = pool_time; 131 143 132 PJ_LOG(3, (THIS_FILE, ".. malloc Speedupbest=%dx, worst=%dx",144 PJ_LOG(3, (THIS_FILE, "..pool speedup over malloc best=%dx, worst=%dx", 133 145 (int)(malloc_time/best), 134 146 (int)(malloc_time/worst)));
Note: See TracChangeset
for help on using the changeset viewer.