| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /*
- * Copyright 2010-2025 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
- */
- #include <bx/timer.h>
- #include <bx/handlealloc.h>
- #include <tinystl/allocator.h>
- #include <tinystl/unordered_map.h>
- #include <unordered_map>
- #include <stdio.h>
- #include <assert.h>
- template<typename MapType>
- bool mapRemove(MapType& _map, const typename MapType::value_type::first_type& _first)
- {
- typename MapType::const_iterator it = _map.find(_first);
- if (it != _map.end() )
- {
- _map.erase(it);
- return true;
- }
- return false;
- }
- int main()
- {
- const uint32_t numElements = 4<<10;
- const uint32_t numIterations = 16;
- //
- {
- int64_t elapsed = -bx::getHPCounter();
- for (uint32_t ii = 0; ii < numIterations; ++ii)
- {
- typedef tinystl::unordered_map<uint64_t, uint16_t> TinyStlUnorderedMap;
- TinyStlUnorderedMap map;
- // map.reserve(numElements);
- for (uint32_t jj = 0; jj < numElements; ++jj)
- {
- tinystl::pair<TinyStlUnorderedMap::iterator, bool> ok = map.insert(tinystl::make_pair(uint64_t(jj), uint16_t(jj) ) );
- assert(ok.second); BX_UNUSED(ok);
- }
- for (uint32_t jj = 0; jj < numElements; ++jj)
- {
- bool ok = mapRemove(map, uint64_t(jj) );
- assert(ok); BX_UNUSED(ok);
- }
- assert(map.size() == 0);
- }
- elapsed += bx::getHPCounter();
- printf(" TinyStl: %15f\n", double(elapsed) );
- }
- ///
- {
- int64_t elapsed = -bx::getHPCounter();
- for (uint32_t ii = 0; ii < numIterations; ++ii)
- {
- typedef std::unordered_map<uint64_t, uint16_t> StdUnorderedMap;
- StdUnorderedMap map;
- map.reserve(numElements);
- for (uint32_t jj = 0; jj < numElements; ++jj)
- {
- std::pair<StdUnorderedMap::iterator, bool> ok = map.insert(std::make_pair(uint64_t(jj), uint16_t(jj) ) );
- assert(ok.second); BX_UNUSED(ok);
- }
- for (uint32_t jj = 0; jj < numElements; ++jj)
- {
- bool ok = mapRemove(map, uint64_t(jj) );
- assert(ok); BX_UNUSED(ok);
- }
- assert(map.size() == 0);
- }
- elapsed += bx::getHPCounter();
- printf(" STL: %15f\n", double(elapsed) );
- }
- ///
- {
- int64_t elapsed = -bx::getHPCounter();
- for (uint32_t ii = 0; ii < numIterations; ++ii)
- {
- typedef bx::HandleHashMapT<numElements+numElements/2, uint64_t> HandleHashMap;
- HandleHashMap map;
- for (uint32_t jj = 0; jj < numElements; ++jj)
- {
- bool ok = map.insert(jj, uint16_t(jj) );
- assert(ok); BX_UNUSED(ok);
- }
- for (uint32_t jj = 0; jj < numElements; ++jj)
- {
- bool ok = map.removeByKey(uint64_t(jj) );
- assert(ok); BX_UNUSED(ok);
- }
- assert(map.getNumElements() == 0);
- }
- elapsed += bx::getHPCounter();
- printf("HandleHashMap: %15f\n", double(elapsed) );
- }
- extern void simd_bench();
- simd_bench();
- extern void math_bench();
- math_bench();
- return bx::kExitSuccess;
- }
|