serge-sans-paille / frozen

a header-only, constexpr alternative to gperf for C++14 users
Apache License 2.0
1.27k stars 103 forks source link

Add benchmark for unordered_map #137

Closed bencsikandrei closed 2 years ago

bencsikandrei commented 2 years ago

Hello!

I was working with your awesome library and needed unordered_map benchmarks to prove a point. Cooked some up and figured you might be interested in them also (or not, which is totally fine by me and we can close this asap ;p).

Please let me know if I somehow missed existing benchmarks for unordered_map.

I started adding string stuff, waiting for you let me know if you want these in and I'd gladly also add some for ints.

Have a good one! Cheers

ddevienne commented 2 years ago

What are the results of those benchmarks, compared to a static const std::[unordered_]map<K, V> map{ ... };? The reason I'm asking is I haven't yet introduced Frozen in our (large) code-base, and would like insights on performance. One has to justify using a new 3rd party library, so just looking for good arguments in favor of Frozen.

bencsikandrei commented 2 years ago

Here's an extract of the benchmarks I ran on my laptop (this is vs std::unordered_map), will update for the rest:

Running ./benchmarks/frozen.benchmark
Run on (12 X 3207.92 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x6)
  L1 Instruction 32 KiB (x6)
  L2 Unified 256 KiB (x6)
  L3 Unified 12288 KiB (x1)
Load Average: 1.23, 0.94, 0.92
------------------------------------------------------------------
Benchmark                        Time             CPU   Iterations
------------------------------------------------------------------
BM_StrInFzUnorderedMap         323 ns          323 ns      2156708
BM_StrInStdUnorderedMap        810 ns          810 ns       814989
BM_StrInStdArray               483 ns          483 ns      1276827

I'd still like to try using string_view instead of frozen::string, just to make sure the comparison is fair. Will also post here.

EDIT: the results are the same with static const std::unordered_map<std::string_view...>

serge-sans-paille commented 2 years ago

Looks good, thanks for your effort o/