Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apps/examples: modify the heap performance test to show the average t… #3348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions apps/examples/heap_performance_test/heap_performance_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ static int heap_performance_test(int argc, char *argv[])
int size = 32;
int i, j, k;
char *data[100];
int test_repeat = 11;
int num_of_sizes = 11;
uint32_t elapsed = 0;
uint32_t total_elapsed = 0;
int sizes[11] = {16, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192};
int interval = 1;
int ucc = 10; // unit changing constant

for (j = 0; j < NUM_ALLOC; ++j) {
data[j] = NULL;
Expand All @@ -53,21 +54,26 @@ static int heap_performance_test(int argc, char *argv[])
interval = in;
}
in = strtol(argv[3], (char **)NULL, 10);
if (in > 0) {
repeat = in;
if (in >= 100000) {
in /= (NUM_ALLOC * 100);
while ((in /= 10) > 0) {
repeat *= 10;
}
ucc = repeat / 10;
}
} else {
printf("Usage: %s param1 param2\n", argv[1]);
printf(" param1 is the interval between tests each of which handles a different size.\n");
printf(" param2 is the number of repetition of one experiment.\n");
printf(" In one experiment, param1-sized memory is allocated a hundred times and then released.\n\n");
printf(" param2 is the number of repetition of one pair of malloc() and free().\n");
printf(" It should be 10^n where n >= 4.\n");
printf("At this time, %s will be performed with default values.\n\n", argv[1]);
}

printf("\nTest with interval %d, repetition %d.\n", interval, repeat);
printf("Elapsed time doing a cycle of malloc() and free() %u times:\n", NUM_ALLOC * repeat);
printf("\nTest with interval %d.\n", interval);
printf("One pair of alloc() and free() has been performed %u times.\n\n", NUM_ALLOC * repeat);
printf("Average time per one pair of malloc() and free():\n");

for (k = 0; k < test_repeat; ++k) {
for (k = 0; k < num_of_sizes; ++k) {
size = sizes[k];
if (clock_gettime(CLOCK_REALTIME, &ts1) == -1) {
printf("gettime error occured.\n");
Expand Down Expand Up @@ -97,7 +103,7 @@ static int heap_performance_test(int argc, char *argv[])
if (k > 0) {
elapsed = ((ts2.tv_sec - ts1.tv_sec) * 1000 + (ts2.tv_nsec - ts1.tv_nsec) / 1000000);
total_elapsed += elapsed;
printf("Size %u bytes : %u mseconds.\n", size, elapsed);
printf("Size %u bytes : %u.%u [us]\n", size, elapsed / ucc, elapsed - (elapsed / ucc) * ucc);
}

sleep(interval);
Expand Down