add test case for phrase table
authorPeng Wu <alexepico@gmail.com>
Thu, 2 Sep 2010 06:32:27 +0000 (14:32 +0800)
committerPeng Wu <alexepico@gmail.com>
Thu, 2 Sep 2010 06:32:27 +0000 (14:32 +0800)
tests/storage/test_phrase_table.cpp
tests/storage/test_pinyin_index.cpp

index 691b1dc..08d1626 100644 (file)
@@ -1,3 +1,4 @@
+#include <string.h>
 #include <stdio.h>
 #include <sys/time.h>
 #include "novel_types.h"
@@ -44,5 +45,30 @@ int main(int argc, char * argv[]){
     largetable.load_text(gbkfile);
     fclose(gbkfile);
 
+    char * linebuf = NULL;
+    size_t size = 0;
+    while( getline(&linebuf, &size, stdin) ){
+        linebuf[strlen(linebuf) - 1] = '\0';
+        if ( strcmp ( linebuf, "quit" ) == 0)
+            break;
 
+        glong phrase_len = g_utf8_strlen(linebuf, -1);
+        utf16_t * new_phrase = g_utf8_to_utf16(linebuf, -1, NULL, NULL, NULL);
+        phrase_token_t token;
+
+        guint32 start = record_time();
+        for ( int i = 0; i < bench_times; ++i){
+            largetable.search(phrase_len, new_phrase, token);
+        }
+        print_time(start, bench_times);
+
+        largetable.search(phrase_len, new_phrase, token);
+        printf("%s:\t%d\n", linebuf, token);
+
+        g_free(new_phrase);
+    }
+
+    if ( linebuf )
+        free(linebuf);
+    return 0;
 }
index ab30dfd..d9a5abf 100644 (file)
@@ -74,8 +74,8 @@ int main( int argc, char * argv[]){
     largetable.store(new_chunk);
     largetable.load(new_chunk);
     
-    char* linebuf = (char *)malloc ( 1024 * sizeof (char) );
-    size_t size = 1024;
+    char* linebuf = NULL;
+    size_t size = 0;
     while( getline(&linebuf, &size, stdin) ){
         linebuf[strlen(linebuf)-1] = '\0';
        if ( strcmp ( linebuf, "quit" ) == 0)
@@ -145,5 +145,7 @@ int main( int argc, char * argv[]){
        g_array_free(keys, TRUE);
        g_array_free(poses, TRUE);
     }
-    free(linebuf);
+    if (linebuf)
+        free(linebuf);
+    return 0;
 }