1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 \*---------------------------------------------------------------------------*/
33 #include "PackedBoolList.H"
35 #include "StaticHashTable.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 int main(int argc, char *argv[])
48 const label n = 1000000;
49 const label nIters = 1000;
53 PackedBoolList packed(n, 1);
54 boolList unpacked(n, true);
55 std::vector<bool> stlVector(n, true);
57 labelHashSet emptyHash;
58 labelHashSet fullHash(1000);
59 for (label i = 0; i < n; i++)
64 // fullStaticHash is really slow
65 // give it lots of slots to help
66 StaticHashTable<nil, label, Hash<label> > emptyStaticHash;
67 StaticHashTable<nil, label, Hash<label> > fullStaticHash(100000);
68 for (label i = 0; i < n; i++)
70 fullStaticHash.insert(i, nil());
73 emptyHash.printInfo(Info);
74 fullHash.printInfo(Info);
75 emptyStaticHash.printInfo(Info);
76 fullStaticHash.printInfo(Info);
81 for (label iter = 0; iter < nIters; ++iter)
87 Info<< "resize/shrink/resize:" << timer.cpuTimeIncrement() << " s\n\n";
89 // set every other bit on:
90 Info<< "set every other bit on and count\n";
91 packed.storage() = 0xAAAAAAAAu;
95 for (label iter = 0; iter < nIters; ++iter)
102 Info<< "Counting brute-force:" << timer.cpuTimeIncrement()
104 Info<< " sum " << sum << endl;
109 for (label iter = 0; iter < nIters; ++iter)
111 sum += packed.count();
113 Info<< "Counting via count():" << timer.cpuTimeIncrement()
115 Info<< " sum " << sum << endl;
120 for (label iter = 0; iter < nIters; ++iter)
127 Info<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << endl;
128 Info<< " sum " << sum << endl;
136 for (label iter = 0; iter < nIters; ++iter)
138 for(unsigned int i = 0; i < stlVector.size(); i++)
143 Info<< "Reading stl:" << timer.cpuTimeIncrement() << " s" << endl;
144 Info<< " sum " << sum << endl;
149 for (label iter = 0; iter < nIters; ++iter)
156 Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << endl;
157 Info<< " sum " << sum << endl;
162 for (label iter = 0; iter < nIters; ++iter)
166 sum += packed.get(i);
169 Info<< "Reading packed using get:" << timer.cpuTimeIncrement()
171 Info<< " sum " << sum << endl;
176 for (label iter = 0; iter < nIters; ++iter)
183 Info<< "Reading packed using reference:" << timer.cpuTimeIncrement()
185 Info<< " sum " << sum << endl;
190 for (label iter = 0; iter < nIters; ++iter)
194 PackedBoolList::iterator it = packed.begin();
202 Info<< "Reading packed using iterator:" << timer.cpuTimeIncrement()
204 Info<< " sum " << sum << endl;
209 for (label iter = 0; iter < nIters; ++iter)
213 PackedBoolList::const_iterator cit = packed.cbegin();
214 cit != packed.cend();
221 Info<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement()
223 Info<< " sum " << sum << endl;
228 for (label iter = 0; iter < nIters; ++iter)
232 sum += emptyHash.found(i);
235 Info<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement()
237 Info<< " sum " << sum << endl;
242 for (label iter = 0; iter < nIters; ++iter)
246 sum += fullHash.found(i);
249 Info<< "Reading full labelHashSet:" << timer.cpuTimeIncrement()
251 Info<< " sum " << sum << endl;
254 // Read empty static hash
256 for (label iter = 0; iter < nIters; ++iter)
260 sum += emptyStaticHash.found(i);
263 Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement()
265 Info<< " sum " << sum << endl;
268 // we can skip this test - it is usually quite slow
269 // Read full static hash
271 for (label iter = 0; iter < nIters; ++iter)
275 sum += fullStaticHash.found(i);
278 Info<< "Reading full StaticHash:" << timer.cpuTimeIncrement()
280 Info<< " sum " << sum << endl;
283 Info<< "Starting write tests" << endl;
290 for (label iter = 0; iter < nIters; ++iter)
292 for (unsigned int i = 0; i < stlVector.size(); i++)
297 Info<< "Writing stl:" << timer.cpuTimeIncrement() << " s" << endl;
300 for (label iter = 0; iter < nIters; ++iter)
307 Info<< "Writing unpacked:" << timer.cpuTimeIncrement() << " s" << endl;
311 for (label iter = 0; iter < nIters; ++iter)
318 Info<< "Writing packed using reference:" << timer.cpuTimeIncrement()
323 for (label iter = 0; iter < nIters; ++iter)
330 Info<< "Writing packed using set:" << timer.cpuTimeIncrement()
335 for (label iter = 0; iter < nIters; ++iter)
339 PackedBoolList::iterator it = packed.begin();
347 Info<< "Writing packed using iterator:" << timer.cpuTimeIncrement()
352 for (label iter = 0; iter < nIters; ++iter)
356 Info<< "Writing packed uniform 0:" << timer.cpuTimeIncrement()
361 for (label iter = 0; iter < nIters; ++iter)
365 Info<< "Writing packed uniform 1:" << timer.cpuTimeIncrement()
369 PackedList<3> oddPacked(n, 3);
372 for (label iter = 0; iter < nIters; ++iter)
376 Info<< "Writing packed<3> uniform 0:" << timer.cpuTimeIncrement()
381 for (label iter = 0; iter < nIters; ++iter)
385 Info<< "Writing packed<3> uniform 1:" << timer.cpuTimeIncrement()
389 Info << "End\n" << endl;
395 // ************************************************************************* //