summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2010-09-01 15:32:15 +0800
committerPeng Wu <alexepico@gmail.com>2010-09-01 15:32:15 +0800
commitcdb3ae7a7bab2970eedae28ee7d1a387847f51fd (patch)
tree2d23658e30d1309382dc12ae299b040c7a286a9f
parent7e544ad0d4261320ad4e2fa3228b9b81ed76ffb0 (diff)
downloadlibpinyin-cdb3ae7a7bab2970eedae28ee7d1a387847f51fd.tar.gz
libpinyin-cdb3ae7a7bab2970eedae28ee7d1a387847f51fd.tar.xz
libpinyin-cdb3ae7a7bab2970eedae28ee7d1a387847f51fd.zip
begin to write phrase large table test case
-rw-r--r--tests/storage/test_phrase_table.cpp48
-rw-r--r--tests/storage/test_pinyin_index.cpp15
2 files changed, 56 insertions, 7 deletions
diff --git a/tests/storage/test_phrase_table.cpp b/tests/storage/test_phrase_table.cpp
new file mode 100644
index 0000000..691b1dc
--- /dev/null
+++ b/tests/storage/test_phrase_table.cpp
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <sys/time.h>
+#include "novel_types.h"
+#include "phrase_large_table.h"
+
+size_t bench_times = 1000;
+
+guint32 record_time ()
+{
+ timeval tv;
+ gettimeofday(&tv, NULL);
+ return (guint32) tv.tv_sec * 1000000 + tv.tv_usec;
+}
+
+void print_time (guint32 old_time, guint32 times)
+{
+ timeval tv;
+ gettimeofday (&tv, NULL);
+
+ guint32 wasted = (guint32) tv.tv_sec * 1000000 + tv.tv_usec - old_time;
+
+ printf("Spent %d us for %d operations, %f us/op, %f times/s.\n\n", wasted, times, ((double)wasted)/times, times * 1000000.0/wasted);
+}
+
+
+int main(int argc, char * argv[]){
+ PhraseLargeTable largetable;
+
+ FILE * gbfile = fopen("../../data/gb_char.table", "r");
+ if ( gbfile == NULL ) {
+ printf("open gb_char.table failed!\n");
+ return 1;
+ }
+
+ largetable.load_text(gbfile);
+ fclose(gbfile);
+
+ FILE * gbkfile = fopen("../../data/gbk_char.table", "r");
+ if (gbkfile == NULL ) {
+ printf("open gbk_char.table failed!\n");
+ return 1;
+ }
+
+ largetable.load_text(gbkfile);
+ fclose(gbkfile);
+
+
+}
diff --git a/tests/storage/test_pinyin_index.cpp b/tests/storage/test_pinyin_index.cpp
index e79eb3b..ab30dfd 100644
--- a/tests/storage/test_pinyin_index.cpp
+++ b/tests/storage/test_pinyin_index.cpp
@@ -1,7 +1,6 @@
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
-#include <glib.h>
#include "novel_types.h"
#include "pinyin_base.h"
#include "pinyin_phrase.h"
@@ -34,18 +33,20 @@ int main( int argc, char * argv[]){
PinyinLargeTable largetable(&custom);
FILE * gbfile = fopen("../../data/gb_char.table", "r");
- if ( gbfile == NULL) {
- printf("open gb_char.table failed!");
+ if ( gbfile == NULL ) {
+ printf("open gb_char.table failed!\n");
return 1;
}
+
+ largetable.load_text(gbfile);
+ fclose(gbfile);
+
FILE * gbkfile = fopen("../../data/gbk_char.table","r");
- if ( gbkfile == NULL) {
- printf("open gb_char.table failed!");
+ if ( gbkfile == NULL ) {
+ printf("open gb_char.table failed!\n");
return 1;
}
- largetable.load_text(gbfile);
- fclose(gbfile);
largetable.load_text(gbkfile);
fclose(gbkfile);