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/Ngram.h | |
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/Ngram.h')
-rw-r--r-- | mert/Ngram.h | 11 |
1 files changed, 6 insertions, 5 deletions
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; }; } |