diff --git a/benchmarks/IndexStd/IndexStd.cpp b/benchmarks/IndexStd/IndexStd.cpp index 06a09b9a7..c29caa4e3 100644 --- a/benchmarks/IndexStd/IndexStd.cpp +++ b/benchmarks/IndexStd/IndexStd.cpp @@ -6,6 +6,16 @@ using namespace Upp; +namespace std { + template<> struct hash + { + std::size_t operator()(const String& k) const + { + return GetHashValue(k); + } + }; +} + CONSOLE_APP_MAIN { StdLogSetup(LOG_COUT|LOG_FILE); @@ -19,26 +29,98 @@ CONSOLE_APP_MAIN for(int i = 0; i < 100; i++) { Index ndx; + SortedIndex ndx2; std::set st; - std::set hst; + std::set sst; + std::unordered_set hst; + std::unordered_set hsst; { RTIMING("Index"); for(const String& s : w) ndx.FindAdd(s); } + { + RTIMING("SortedIndex"); + for(const String& s : w) + ndx2.FindAdd(s); + } { RTIMING("set"); for(const std::string& s : q) st.insert(s); } + { + RTIMING("set String"); + for(const String& s : w) + sst.insert(s); + } { RTIMING("unordered_set"); for(const std::string& s : q) hst.insert(s); } + { + RTIMING("unordered_set String"); + for(const String& s : w) + hsst.insert(s); + } ONCELOCK { RDUMP(ndx.GetCount()); + RDUMP(ndx2.GetCount()); RDUMP(st.size()); + RDUMP(sst.size()); + RDUMP(hst.size()); + } + } + + w = AliceLines(); + + q.clear(); + for(auto s : w) + q.push_back(s.ToStd()); + + for(int i = 0; i < 100; i++) { + Index ndx; + SortedIndex ndx2; + std::set st; + std::set sst; + std::unordered_set hst; + std::unordered_set hsst; + { + RTIMING("Index"); + for(const String& s : w) + ndx.FindAdd(s); + } + { + RTIMING("SortedIndex"); + for(const String& s : w) + ndx2.FindAdd(s); + } + { + RTIMING("set"); + for(const std::string& s : q) + st.insert(s); + } + { + RTIMING("set String"); + for(const String& s : w) + sst.insert(s); + } + { + RTIMING("unordered_set"); + for(const std::string& s : q) + hst.insert(s); + } + { + RTIMING("unordered_set String"); + for(const String& s : w) + hsst.insert(s); + } + ONCELOCK { + RDUMP(ndx.GetCount()); + RDUMP(ndx2.GetCount()); + RDUMP(st.size()); + RDUMP(sst.size()); RDUMP(hst.size()); } } diff --git a/benchmarks/IndexStd/IndexStd.upp b/benchmarks/IndexStd/IndexStd.upp index 906703c87..0676d27cc 100644 --- a/benchmarks/IndexStd/IndexStd.upp +++ b/benchmarks/IndexStd/IndexStd.upp @@ -6,5 +6,6 @@ file IndexStd.cpp; mainconfig - "" = ""; + "" = "", + "" = "USEMALLOC"; diff --git a/benchmarks/Sort/Sort.cpp b/benchmarks/Sort/Sort.cpp index a19e4e8c1..f6ec89248 100644 --- a/benchmarks/Sort/Sort.cpp +++ b/benchmarks/Sort/Sort.cpp @@ -12,8 +12,8 @@ CONSOLE_APP_MAIN RDUMP(AliceWords().GetCount()); for(int i = 0; i < 300; i++) { Vector w = AliceWords(); + std::vector x; { - std::vector x; for(auto s : w) x.push_back(s.ToStd()); RTIMING("std::sort std::vector"); @@ -21,17 +21,21 @@ CONSOLE_APP_MAIN } Vector w2 = clone(w); { - RTIMING("StableSort Vector"); - StableSort(w2); + RTIMING("Sort Vector"); + Sort(w2); } - { + + for(int i = 0; i < w2.GetCount(); i++) + if(w2[i] != x[i]) + Panic("Failed!"); +/* { std::vector x; for(auto s : w) x.push_back(s.ToStd()); RTIMING("std::sort std::vector"); std::stable_sort(x.begin(), x.end()); } - #if 0 +*/ #if 0 ONCELOCK { RDUMPC(w); } diff --git a/benchmarks/Sort2/Sort2.cpp b/benchmarks/Sort2/Sort2.cpp index 47c8462c5..ec2e7187e 100644 --- a/benchmarks/Sort2/Sort2.cpp +++ b/benchmarks/Sort2/Sort2.cpp @@ -84,7 +84,7 @@ CONSOLE_APP_MAIN double t = tm.Seconds(); RLOG(n << " " << t << " s"); } - +/* Buffer aq(N); RLOG("Generating antiqsort"); antiqsort(N, aq); @@ -96,4 +96,5 @@ CONSOLE_APP_MAIN Sort(h); double t = tm.Seconds(); RLOG("antiqsort " << t << " s"); +*/ }