2017-04-11 08:16:10 +02:00
|
|
|
/*
|
2018-02-03 17:39:28 +01:00
|
|
|
* Copyright 2010-2018 Branimir Karadzic. All rights reserved.
|
2017-04-11 08:16:10 +02:00
|
|
|
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
|
|
|
|
*/
|
|
|
|
|
2016-11-10 21:53:08 +01:00
|
|
|
#include <bx/timer.h>
|
|
|
|
#include <bx/handlealloc.h>
|
|
|
|
#include <bx/maputil.h>
|
|
|
|
|
|
|
|
#include <tinystl/allocator.h>
|
|
|
|
#include <tinystl/unordered_map.h>
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
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) ) );
|
2017-04-11 08:16:10 +02:00
|
|
|
assert(ok.second); BX_UNUSED(ok);
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t jj = 0; jj < numElements; ++jj)
|
|
|
|
{
|
|
|
|
bool ok = bx::mapRemove(map, uint64_t(jj) );
|
2017-04-11 08:16:10 +02:00
|
|
|
assert(ok); BX_UNUSED(ok);
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) ) );
|
2017-04-11 08:16:10 +02:00
|
|
|
assert(ok.second); BX_UNUSED(ok);
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t jj = 0; jj < numElements; ++jj)
|
|
|
|
{
|
|
|
|
bool ok = bx::mapRemove(map, uint64_t(jj) );
|
2017-04-11 08:16:10 +02:00
|
|
|
assert(ok); BX_UNUSED(ok);
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) );
|
2017-04-11 08:16:10 +02:00
|
|
|
assert(ok); BX_UNUSED(ok);
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t jj = 0; jj < numElements; ++jj)
|
|
|
|
{
|
|
|
|
bool ok = map.removeByKey(uint64_t(jj) );
|
2017-04-11 08:16:10 +02:00
|
|
|
assert(ok); BX_UNUSED(ok);
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(map.getNumElements() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
elapsed += bx::getHPCounter();
|
|
|
|
printf("HandleHashMap: %15f\n", double(elapsed) );
|
|
|
|
}
|
|
|
|
|
2017-04-11 08:16:10 +02:00
|
|
|
extern void simd_bench();
|
|
|
|
simd_bench();
|
|
|
|
|
2018-02-03 17:39:28 +01:00
|
|
|
extern void math_bench();
|
|
|
|
math_bench();
|
|
|
|
|
|
|
|
return bx::kExitSuccess;
|
2016-11-10 21:53:08 +01:00
|
|
|
}
|