# HG changeset patch # User Shohei KOKUBO # Date 1430210384 -32400 # Node ID 4c3c0ad4a75d13e3c87522c20afb7dfc5f7cfc8b # Parent 737a900518beae6f85846f9dd35f013c83d159d1 add benchmark method diff -r 737a900518be -r 4c3c0ad4a75d src/llrb/llrb.c --- a/src/llrb/llrb.c Tue Apr 28 14:34:59 2015 +0900 +++ b/src/llrb/llrb.c Tue Apr 28 17:39:44 2015 +0900 @@ -1,5 +1,6 @@ #include #include +#include #include "llrbContext.h" @@ -12,7 +13,7 @@ #endif #define NUM 100 -#define ALLOCATE_SIZE 1024 +#define ALLOCATE_SIZE 1000000000 extern __code initLLRBContext(struct Context* context); void colorFlip(struct Context*); @@ -25,6 +26,25 @@ goto Allocate(allocate); } */ +static double st_time; +static double ed_time; +static int num; + +static double getTime() { + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + (double)tv.tv_usec*1e-6; +} + +void print_tree(union Data* data, int n) { + if (data != 0) { + print_tree(data->node.left, n+1); + for (int i=0;inode.key); + print_tree(data->node.right, n+1); + } +} __code code1(struct Context* context) { context->data[0]->allocate.size = sizeof(long); @@ -164,8 +184,9 @@ } __code code3(struct Context* context) { - if (context->data[1]->count == NUM) - goto meta(context, Exit); + if (context->data[1]->count == num) { + goto meta(context, Code4); + } context->data[0]->allocate.size = sizeof(struct Node); context->data[0]->allocate.next = Put; context->data[0]->allocate.after_put = Code3; @@ -175,7 +196,26 @@ goto meta(context, Allocate); } -int main() { +__code code4(struct Context* context) { + st_time = getTime(); + context->data[0]->allocate.size = sizeof(struct Node); + context->data[0]->allocate.next = Put; + context->data[0]->allocate.after_put = Code5; + context->data[0]->allocate.key = num+1; + context->data[0]->allocate.value = num+1; + + goto meta(context, Allocate); +} + +__code code5(struct Context* context) { + ed_time = getTime(); + // printf("%ld %0.12f\n", context->data[1]->count-1, ed_time-st_time); + print_tree(context->root, 0); + goto meta(context, Exit); +} + +int main(int argc, char** argv) { + num = (int)atoi(argv[1]); struct Context* context = (struct Context*)malloc(sizeof(struct Context)); context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); context->data = malloc(sizeof(union Data**)*ALLOCATE_SIZE); diff -r 737a900518be -r 4c3c0ad4a75d src/llrb/llrbContext.c --- a/src/llrb/llrbContext.c Tue Apr 28 14:34:59 2015 +0900 +++ b/src/llrb/llrbContext.c Tue Apr 28 17:39:44 2015 +0900 @@ -2,6 +2,8 @@ extern __code code1(struct Context*); extern __code code2(struct Context*); extern __code code3(struct Context*); +extern __code code4(struct Context*); +extern __code code5(struct Context*); extern __code meta(struct Context*); extern __code allocate(struct Context*); extern __code put(struct Context*); @@ -14,6 +16,8 @@ context->code[Code1] = code1; context->code[Code2] = code2; context->code[Code3] = code3; + context->code[Code4] = code4; + context->code[Code5] = code5; context->code[Allocate] = allocate; context->code[Put] = put; context->code[InsertD] = insertDown; diff -r 737a900518be -r 4c3c0ad4a75d src/llrb/llrbContext.h --- a/src/llrb/llrbContext.h Tue Apr 28 14:34:59 2015 +0900 +++ b/src/llrb/llrbContext.h Tue Apr 28 17:39:44 2015 +0900 @@ -4,6 +4,8 @@ Code1, Code2, Code3, + Code4, + Code5, Allocate, Put, InsertD,