HashTable performance: find(), found() check nElmts_ instead of tableSize_

- much better performance on empty tables (4-6x speedup), neutral
  performance change on filled tables. Since tableSize_ is non-zero when
  nElmts_ is, there is no modulus zero problem.
This commit is contained in:
Mark Olesen
2009-02-25 18:58:48 +01:00
parent 9c8432a002
commit e562aecb73
8 changed files with 94 additions and 48 deletions

View File

@ -32,6 +32,7 @@ Description
#include "boolList.H"
#include "PackedBoolList.H"
#include "HashSet.H"
#include "StaticHashTable.H"
#include "cpuTime.H"
#include <vector>
@ -55,11 +56,14 @@ int main(int argc, char *argv[])
labelHashSet emptyHash;
labelHashSet fullHash(1000);
for(label i = 0; i < n; i++)
for (label i = 0; i < n; i++)
{
fullHash.insert(i);
}
// don't use fullStaticHash, it's too slow
StaticHashTable<nil, label, Hash<label> > emptyStaticHash;
cpuTime timer;
for (label iter = 0; iter < nIters; ++iter)
@ -235,6 +239,22 @@ int main(int argc, char *argv[])
Info<< " sum " << sum << endl;
// Read empty static hash
sum = 0;
for (label iter = 0; iter < nIters; ++iter)
{
forAll(unpacked, i)
{
sum += emptyStaticHash.found(i);
}
}
Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement()
<< " s" << endl;
Info<< " sum " << sum << endl;
Info<< "Starting write tests" << endl;
//
// Write
//