changeset 22:4c3c0ad4a75d

add benchmark method
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 28 Apr 2015 17:39:44 +0900
parents 737a900518be
children 868c2918b634
files src/llrb/llrb.c src/llrb/llrbContext.c src/llrb/llrbContext.h
diffstat 3 files changed, 50 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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 <stdio.h>
 #include <stdlib.h>
+#include <sys/time.h>
 
 #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;i<n;i++)
+            printf("  ");
+        printf("key=%d\n", data->node.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);
--- 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;
--- 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,