1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include "data/HashMap.h"
- #include "data/ProbingHashMap.h"
- #include "test/Test.h"
- #include "utils/Clock.h"
- template<typename Map>
- static void test(const Map& m) {
- Core::Clock::Nanos nanos = 0;
- CORE_TEST_ERROR(Core::Clock::getNanos(nanos));
- int sum = 0;
- for(int i = 0; i < 10000; i++) {
- for(int k = -5000; k < 5000; k++) {
- const int* s = m.search(i + k);
- if(s != nullptr) {
- sum += *s;
- }
- }
- }
- Core::Clock::Nanos nanos2 = 0;
- CORE_TEST_ERROR(Core::Clock::getNanos(nanos2));
- CORE_LOG_INFO("# | # ns", sum, nanos2 - nanos);
- }
- int main() {
- Core::HashMap<int, int> m;
- Core::ProbingHashMap<int, int> m2(1 << 30);
- for(int i = 0; i < 10000; i++) {
- CORE_TEST_ERROR(m.add(i, i * i));
- CORE_TEST_ERROR(m2.add(i, i * i));
- }
- test(m);
- test(m);
- test(m);
- test(m2);
- test(m2);
- test(m2);
- return 0;
- }
|