summaryrefslogtreecommitdiffstats
path: root/tests/storage/test_phrase_table.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2010-09-02 14:32:27 +0800
committerPeng Wu <alexepico@gmail.com>2010-09-02 14:32:27 +0800
commit82cbc78740e1bf34514137eddba58fa16e9788ac (patch)
tree511a8f8aaf0667e8040a7acab982d7d4d508419f /tests/storage/test_phrase_table.cpp
parentbee691f0e31f0b661f7c2c16230163dd7d526d4c (diff)
downloadlibpinyin-82cbc78740e1bf34514137eddba58fa16e9788ac.tar.gz
libpinyin-82cbc78740e1bf34514137eddba58fa16e9788ac.tar.xz
libpinyin-82cbc78740e1bf34514137eddba58fa16e9788ac.zip
add test case for phrase table
Diffstat (limited to 'tests/storage/test_phrase_table.cpp')
-rw-r--r--tests/storage/test_phrase_table.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/storage/test_phrase_table.cpp b/tests/storage/test_phrase_table.cpp
index 691b1dc..08d1626 100644
--- a/tests/storage/test_phrase_table.cpp
+++ b/tests/storage/test_phrase_table.cpp
@@ -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;
}