From e6d099d057c7a2a780621ffe48e112f9f8f1c678 Mon Sep 17 00:00:00 2001 From: strange Date: Sun, 31 Jan 2010 22:52:40 -0700 Subject: [PATCH] Alright, then. Time for some major profiling in the monitor. When aesalon is run on the new test, the Fibonacci benchmark, it performs a slowdown of about, oh, 632.7 times more -- 632600% for those who prefer percentages. When run normally, the benchmark takes about 0.015 seconds to execute. When run through aesalon, it takes over eight seconds . . . Time for gprof, methinks. --- monitor/src/CMakeLists.txt | 2 +- tests/.gitignore | 2 +- tests/CMakeLists.txt | 2 + tests/fib_benchmark.c | 104 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 tests/fib_benchmark.c diff --git a/monitor/src/CMakeLists.txt b/monitor/src/CMakeLists.txt index f6f1349..9214e86 100644 --- a/monitor/src/CMakeLists.txt +++ b/monitor/src/CMakeLists.txt @@ -1,5 +1,5 @@ add_definitions(-std=c++0x -W -Wall -ansi -pedantic -Wno-unused-parameter -Wno-long-long -DDEFAULT_PORT=${DEFAULT_PORT} -DLIBC_PATH="${LIBC_PATH}") -add_definitions(-DAESALON_MAJOR_VERSION=${AESALON_MAJOR_VERSION} -DAESALON_MINOR_VERSION=${AESALON_MINOR_VERSION} -DAESALON_PATCHLEVEL=${AESALON_PATCHLEVEL} -DAESALON_PLATFORM=${AESALON_PLATFORM}) +add_definitions(-DAESALON_MAJOR_VERSION="${AESALON_MAJOR_VERSION}" -DAESALON_MINOR_VERSION="${AESALON_MINOR_VERSION}" -DAESALON_PATCHLEVEL="${AESALON_PATCHLEVEL}" -DAESALON_PLATFORM=${AESALON_PLATFORM}) add_definitions(-DAESALON_PLATFORM_x86=0 -DAESALON_PLATFORM_x86_64=1) if(DEVELOPMENT_BUILD) diff --git a/tests/.gitignore b/tests/.gitignore index 7f1eb27..5b22661 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -3,4 +3,4 @@ sleep_test sleep_malloc interactive_malloc_test realloc_test - +fib_benchmark diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 56672ba..8b8d77e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,3 +5,5 @@ add_executable(sleep_malloc sleep_malloc.c) add_executable(interactive_malloc_test interactive_malloc_test.c) add_executable(realloc_test realloc_test.c) add_executable(cpp_new_test cpp_new_test.cpp) +add_executable(fib_benchmark fib_benchmark.c) +target_link_libraries(fib_benchmark m) diff --git a/tests/fib_benchmark.c b/tests/fib_benchmark.c new file mode 100644 index 0000000..275a176 --- /dev/null +++ b/tests/fib_benchmark.c @@ -0,0 +1,104 @@ +#include +#include +#include + +#define MAX 1000 + +struct number_t { + char *data; + int data_size; + int sign; +}; + +struct number_t number_from_int(int value); +struct number_t add_numbers(struct number_t one, struct number_t two); +void normalize(struct number_t *number); +char *print_number(struct number_t number); + +struct number_t number_from_int(int value) { + struct number_t result; + result.data = NULL; + result.sign = (value>0?1:-1); + value *= result.sign; + int digit = 0; + while(value > 0) { + result.data = realloc(result.data, sizeof(char) * (digit+1)); + result.data[digit] = (value / (int)pow(10, digit)) % 10; + value -= powl(10, digit)*result.data[digit]; + digit ++; + } + result.data_size = digit; + return result; +} + +struct number_t add_numbers(struct number_t one, struct number_t two) { + struct number_t added; + added.data = NULL; + added.sign = 1; + added.data_size = 0; + int x, max; + if(!one.data_size) return two; + else if(!two.data_size) return one; + + if(one.data_size > two.data_size) max = one.data_size; + else max = two.data_size; + + for(x = 0; x < max; x ++) { + added.data = realloc(added.data, sizeof(char) + (x+1)); + added.data[x] = 0; + if(x < one.data_size) added.data[x] += one.data[x]; + if(x < two.data_size) added.data[x] += two.data[x]; + } + added.data_size = x; + normalize(&added); + return added; +} + +void normalize(struct number_t *number) { + int x = 0; + for(; x < number->data_size-1; x ++) { + while(number->data[x] > 9) { + number->data[x+1] ++; + number->data[x] -= 10; + } + } + while(number->data[number->data_size-1] > 9) { + number->data = realloc(number->data, sizeof(char) * (++number->data_size)); + number->data[number->data_size-1] = 1; + number->data[number->data_size-2] -= 10; + } + +} + +char *print_number(struct number_t number) { + static char buffer[65536]; + int x; + for(x = 0; x < number.data_size; x ++) { + buffer[x] = number.data[(number.data_size-1)-x] + '0'; + } + buffer[number.data_size] = 0; + return buffer; +} + +int main(int argc, char *argv[]) { + struct number_t *fib_numbers, temp; + int x = 0; + fib_numbers = malloc(sizeof(struct number_t) * 2); + fib_numbers[0] = number_from_int(1); + fib_numbers[1] = number_from_int(1); + + for(; x < MAX; x ++) { + fib_numbers = realloc(fib_numbers, sizeof(struct number_t) * (x+3)); + fib_numbers[x+2] = add_numbers(fib_numbers[x], fib_numbers[x+1]); + if(!(x%1000)) printf("Calculated %dth fibonacci . . .\n", x+3); + } + + printf("%ith fibonacci number is %s.\n", x, print_number(fib_numbers[x-1])); + + for(x = 0; x < MAX+2; x ++) { + free(fib_numbers[x].data); + } + + free(fib_numbers); + return 0; +} -- 2.11.4.GIT