[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] std::unordered_map vs std::map
From: |
Greg Chicares |
Subject: |
[lmi] std::unordered_map vs std::map |
Date: |
Sat, 6 Oct 2018 21:13:42 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 |
Interestingly, I see virtually no performance difference in
$make $coefficiency unit_tests unit_test_targets=ledger_test.exe |grep evalu
make_evaluator() : 1.572e-001 s mean; 150181 us least of 7 runs
if I
%s/unordered_//g
as in the patch below. My measurements:
150 ms std::map
148 ms std::unordered_map
I don't plan to apply this patch, because there doesn't seem to be any
benefit, at least not with this compiler:
$i686-w64-mingw32-g++ -dumpversion
7.3-win32
---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
diff --git a/ledger_evaluator.cpp b/ledger_evaluator.cpp
index 4213e918..b2b97458 100644
--- a/ledger_evaluator.cpp
+++ b/ledger_evaluator.cpp
@@ -51,7 +51,7 @@
#include <functional> // minus
#include <map>
#include <numeric> // iota()
-#include <unordered_map>
+#include <map>
#include <utility> // move(), pair
namespace
@@ -75,9 +75,9 @@ std::vector<std::string> const suffixes
// PDF !! Three maps, with similar but not necessarily identical
// sets of keys, may not be the best imaginable data structure.
-typedef std::unordered_map<std::string, std::pair<int,oenum_format_style>>
format_map_t;
-typedef std::unordered_map<std::string, std::string> title_map_t;
-typedef std::unordered_map<std::string, std::string> mask_map_t;
+typedef std::map<std::string, std::pair<int,oenum_format_style>> format_map_t;
+typedef std::map<std::string, std::string> title_map_t;
+typedef std::map<std::string, std::string> mask_map_t;
// For all numbers (so-called 'scalars' and 'vectors', but not
// 'strings') grabbed from all ledgers, look for a format. If one
@@ -859,8 +859,8 @@ ledger_evaluator Ledger::make_evaluator() const
// Maps to hold the results of formatting numeric data.
- std::unordered_map<std::string,std::string> stringscalars;
- std::unordered_map<std::string,std::vector<std::string>> stringvectors;
+ std::map<std::string,std::string> stringscalars;
+ std::map<std::string,std::vector<std::string>> stringvectors;
stringvectors["FundNames"] = invar.FundNames;
diff --git a/ledger_evaluator.hpp b/ledger_evaluator.hpp
index 1a2230bc..63cb05c2 100644
--- a/ledger_evaluator.hpp
+++ b/ledger_evaluator.hpp
@@ -29,7 +29,7 @@
#include <boost/filesystem/path.hpp>
#include <string>
-#include <unordered_map>
+#include <map>
#include <vector>
/// Class allowing to retrieve the string representation of any scalar or
@@ -39,7 +39,7 @@ class LMI_SO ledger_evaluator
{
friend class Ledger;
- template<typename K, typename T> using umap = std::unordered_map<K,T>;
+ template<typename K, typename T> using umap = std::map<K,T>;
using scalar_map_t = umap<std::string, std::string >;
using vector_map_t = umap<std::string,std::vector<std::string>>;
--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------
- [lmi] std::unordered_map vs std::map,
Greg Chicares <=