Implement the UnorderedMap and UnorderedSet containers based on Swisstable, has the same interface as STL(support mostly), and is 2 to 1000 times faster than STL.
The implementation is more concise than the official one, and you can directly include the header file to use.
g++ -O2 -std=c++17 ./perf_test.cpp -o perf_test
|
x86_64 - cpu: 16 Intel(R) Xeon(R) Gold 6161 CPU @ 2.20GHz - memory: 64G |
ARM - cpu: Neoverse N2 - memory: 32G |
|
|---|---|---|
| insert |
|
|
| find |
|
|
| erase |
|
|
| clear |
|
|
| iterate |
|
|
#include "swisstable.h"
int main() {
UnorderedMap<int, int> m;
for (size_t i = 0; i < 100; ++i) {
m.try_empace(i, i);
}
for (size_t i = 0; i < 100; ++i) {
m.find(i);
}
size_t sum = 0;
auto cal_sum = [&sum](HashPair<int, int> &pair) {
sum += pair.second;
};
map.ctraverse(map.cbegin(), map.cend(), cal_sum);
for (size_t i = 0; i < 100; ++i) {
m.erase(i);
}
}








