Speed of hash tables compared to lua
ikod
igor.khasilev at gmail.com
Sun Sep 13 11:23:31 UTC 2020
On Sunday, 13 September 2020 at 10:20:06 UTC, Domingo wrote:
>
> And here is the C++ using unordered map, c++ speed is equal to
> Lua but uses more memory:
>
> =====
> #include <unordered_map>
> #include <string>
> #include <cstdio>
> int main()
> {
> const int DSIZE = 6000008;
> // Create an empty unordered_map
> std::unordered_map<int, double> intMap;
>
> for (int i = 0; i < DSIZE; ++i)
> {
> intMap.insert( { i, (i % 2) == 0 ? 0.0000000123 :
> 12345.0000000001 });
> }
>
> double sum = 0.0;
> for (std::pair<int, double> element : intMap)
> sum += element.second;
>
> printf("count: %d, sum: %35.15f\n", DSIZE, sum);
> return 0;
> }
> =====
> =====
> g++ -O2 -o sum_test_aa-cpp sum_test_aa.cpp
>
> /usr/bin/time ./sum_test_aa-cpp
> count: 6000008, sum: 37035049380.000160217285156
> 0.49user 0.09system 0:00.59elapsed 99%CPU (0avgtext+0avgdata
> 330508maxresident)k
> 0inputs+0outputs (0major+93595minor)pagefaults 0swaps
>
> =====
Default runtime map provide some properties which may be
unavailable for other implementations. Its speed may be affected
by GC, it uses to keep table items.
You may include some hash map implementations from the dub repo
in your benchmark.
More information about the Digitalmars-d
mailing list