diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-12-06 17:08:33 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-12-06 17:08:33 +0400 |
commit | ac045a11c1f0e1d4ae25f0db47061113fc3ae2e1 (patch) | |
tree | 1a6e5fad38dcc3c37852d84cd944f723f2fb4aec /mert | |
parent | 55f65c3104989c5dae13f1cda3395cd52d62c524 (diff) |
Speed up N-gram counts when running extractor.
By replacing std::map with boost::unordered_map.
Runtime of extractor on 100-best lists of 2679 sentences:
Before:
real 0m35.314s
user 0m34.030s
sys 0m1.280s
Ater:
real 0m26.729s
user 0m25.420s
sys 0m1.310s
Diffstat (limited to 'mert')
-rw-r--r-- | mert/BleuScorer.cpp | 1 | ||||
-rw-r--r-- | mert/Ngram.h | 11 |
2 files changed, 7 insertions, 5 deletions
diff --git a/mert/BleuScorer.cpp b/mert/BleuScorer.cpp index ba662680c..a3ba16b13 100644 --- a/mert/BleuScorer.cpp +++ b/mert/BleuScorer.cpp @@ -62,6 +62,7 @@ size_t BleuScorer::CountNgrams(const string& line, NgramCounts& counts, } for (size_t i = 0; i < encoded_tokens.size()-k+1; ++i) { vector<int> ngram; + ngram.reserve(encoded_tokens.size()); for (size_t j = i; j < i+k && j < encoded_tokens.size(); ++j) { ngram.push_back(encoded_tokens[j]); } diff --git a/mert/Ngram.h b/mert/Ngram.h index d3e8041a3..811f21f27 100644 --- a/mert/Ngram.h +++ b/mert/Ngram.h @@ -2,12 +2,13 @@ #define MERT_NGRAM_H_ #include <vector> -#include <map> #include <string> +#include <boost/unordered_map.hpp> + namespace MosesTuning { - + /** A simple STL-std::map based n-gram counts. Basically, we provide * typical accessors and mutaors, but we intentionally does not allow * erasing elements. @@ -35,8 +36,8 @@ class NgramCounts { typedef std::vector<int> Key; typedef int Value; - typedef std::map<Key, Value, NgramComparator>::iterator iterator; - typedef std::map<Key, Value, NgramComparator>::const_iterator const_iterator; + typedef boost::unordered_map<Key, Value>::iterator iterator; + typedef boost::unordered_map<Key, Value>::const_iterator const_iterator; NgramCounts() : kDefaultCount(1) { } virtual ~NgramCounts() { } @@ -95,7 +96,7 @@ class NgramCounts { private: const int kDefaultCount; - std::map<Key, Value, NgramComparator> m_counts; + boost::unordered_map<Key, Value> m_counts; }; } |