openfoam/applications/test/HashTable3/hashTableTest3.C
Mark Olesen 1fbcb6e2c0 Added HashTbl::shrink() - but it only be useful in particular situations
- for the hashTableTest3, it seemed to slow things down a bit

loop 0 - Erased 100000 elements (size 2900000 capacity 4194304) 0.31 s
loop 1 - Erased 100000 elements (size 2800000 capacity 4194304) 0.01 s
loop 2 - Erased 100000 elements (size 2700000 capacity 4194304) 0 s
loop 3 - Erased 100000 elements (size 2600000 capacity 4194304) 0 s
loop 4 - Erased 100000 elements (size 2500000 capacity 4194304) 0.01 s
loop 5 - Erased 100000 elements (size 2400000 capacity 4194304) 0 s
loop 6 - Erased 100000 elements (size 2300000 capacity 4194304) 0 s
loop 7 - Erased 100000 elements (size 2200000 capacity 4194304) 0 s
loop 8 - Erased 100000 elements (size 2100000 capacity 4194304) 0.01 s
loop 9 - Erased 100000 elements (size 2000000 capacity 4194304) 0.44 s
loop 10 - Erased 100000 elements (size 1900000 capacity 4194304) 0.44 s
loop 11 - Erased 100000 elements (size 1800000 capacity 4194304) 0.39 s
loop 12 - Erased 100000 elements (size 1700000 capacity 4194304) 0.4 s
loop 13 - Erased 100000 elements (size 1600000 capacity 2097152) 0.15 s
loop 14 - Erased 100000 elements (size 1500000 capacity 2097152) 0.01 s
loop 15 - Erased 100000 elements (size 1400000 capacity 2097152) 0 s
loop 16 - Erased 100000 elements (size 1300000 capacity 2097152) 0 s
loop 17 - Erased 100000 elements (size 1200000 capacity 2097152) 0.01 s
loop 18 - Erased 100000 elements (size 1100000 capacity 2097152) 0 s
loop 19 - Erased 100000 elements (size 1000000 capacity 2097152) 0.27 s
loop 20 - Erased 100000 elements (size 900000 capacity 2097152) 0.2 s
loop 21 - Erased 100000 elements (size 800000 capacity 1048576) 0.1 s
loop 22 - Erased 100000 elements (size 700000 capacity 1048576) 0 s
loop 23 - Erased 100000 elements (size 600000 capacity 1048576) 0 s
loop 24 - Erased 100000 elements (size 500000 capacity 1048576) 0.12 s
loop 25 - Erased 100000 elements (size 400000 capacity 524288) 0.04 s
loop 26 - Erased 100000 elements (size 300000 capacity 524288) 0.01 s
loop 27 - Erased 100000 elements (size 200000 capacity 262144) 0.02 s
loop 28 - Erased 100000 elements (size 100000 capacity 131072) 0.02 s
loop 29 - Erased 100000 elements (size 0 capacity 2) 0 s
2009-10-30 19:28:39 +01:00

88 lines
2.8 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
Test speeds for some HashTable operations
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "HashTable.H"
#include "HashPtrTable.H"
#include "Map.H"
#include "StaticHashTable.H"
#include "HashTbl.H"
#include "cpuTime.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
const label nLoops = 30;
const label nBase = 100000;
const label nSize = nLoops * nBase;
cpuTime timer;
// ie, a
// Map<label> map(2 * nSize);
// HashTable<label, label, Hash<label> > map(2 * nSize);
// StaticHashTable<label, label, Hash<label> > map(2 * nSize);
HashTbl<label, label, Hash<label> > map(2 * nSize);
Info<< "Constructed map of size: " << nSize
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< " " << timer.cpuTimeIncrement() << " s\n\n";
for (label i = 0; i < nSize; i++)
{
map.insert(i, i);
}
Info<< "Inserted " << nSize << " elements"
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< timer.cpuTimeIncrement() << " s\n";
label elemI = 0;
for (label iLoop = 0; iLoop < nLoops; iLoop++)
{
for (label i = 0; i < nBase; i++)
{
map.erase(elemI++);
}
map.shrink();
Info<< "loop " << iLoop << " - Erased " << nBase << " elements"
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< timer.cpuTimeIncrement() << " s\n";
}
return 0;
}
// ************************************************************************* //