From bbaa8b684d2afbafc0ac3d94f5eb54519b6c77f0 Mon Sep 17 00:00:00 2001 From: wyy Date: Sat, 21 Dec 2013 20:08:40 -0800 Subject: [PATCH] modify load_test --- src/Limonp/io_functs.hpp | 8 +++--- test/CMakeLists.txt | 2 +- test/load_test.cpp | 51 +++++++++++++++++++++++++++++++++++++++ test/test_performance.cpp | 38 ----------------------------- 4 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 test/load_test.cpp delete mode 100644 test/test_performance.cpp diff --git a/src/Limonp/io_functs.hpp b/src/Limonp/io_functs.hpp index 0128e62..ad8824c 100644 --- a/src/Limonp/io_functs.hpp +++ b/src/Limonp/io_functs.hpp @@ -10,17 +10,17 @@ namespace Limonp { using namespace std; - inline string loadFile2Str(const char * const filepath) + inline bool loadFile2Str(const char * const filepath, string& res) { ifstream in(filepath); if(!in) { - return ""; + return false; } istreambuf_iterator beg(in), end; - string str(beg, end); + res.assign(beg, end); in.close(); - return str; + return true; } inline void loadStr2File(const char * const filename, ios_base::openmode mode, const string& str) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ebafbdc..8b35898 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,5 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test) ADD_EXECUTABLE(segment.demo segment.cpp) -ADD_EXECUTABLE(test_performance test_performance.cpp) +ADD_EXECUTABLE(load_test load_test.cpp) ADD_SUBDIRECTORY(unittest) diff --git a/test/load_test.cpp b/test/load_test.cpp new file mode 100644 index 0000000..003d2b2 --- /dev/null +++ b/test/load_test.cpp @@ -0,0 +1,51 @@ +#include +#include +#include "../src/Limonp/ArgvContext.hpp" +#include "../src/MPSegment.hpp" +#include "../src/HMMSegment.hpp" +#include "../src/MixSegment.hpp" + +using namespace CppJieba; + +void cut(const ISegment * seg, const char * const filePath, size_t times = 10) +{ + ifstream ifile(filePath); + if(!ifile) + { + LogFatal("open file[%s] failed.", filePath); + return; + } + LogInfo("open file[%s].", filePath); + vector res; + string doc; + loadFile2Str(filePath, doc); + for(uint i = 0; i < times; i ++) + { + LogInfo("times[%u]", i); + //ifile.seekg(0); + //while(getline(ifile, line)) + //{ + // if(!line.empty()) + // { + res.clear(); + seg->cut(doc, res); + //print(res); + //cout< -#include -#include "../src/Limonp/ArgvContext.hpp" -#include "../src/MPSegment.hpp" -#include "../src/HMMSegment.hpp" -#include "../src/MixSegment.hpp" - -using namespace CppJieba; - -void cut(const ISegment * seg, const char * const filePath) -{ - ifstream ifile(filePath); - vector res; - string line; - while(getline(ifile, line)) - { - if(!line.empty()) - { - res.clear(); - seg->cut(line, res); - //cout<