1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 \*---------------------------------------------------------------------------*/
32 #include "PackedBoolList.H"
34 #include "StaticHashTable.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 int main(int argc, char *argv[])
47 const label n = 1000000;
48 const label nIters = 1000;
52 PackedBoolList packed(n, 1);
53 boolList unpacked(n, true);
54 std::vector<bool> stlVector(n, true);
56 labelHashSet emptyHash;
57 labelHashSet fullHash(1000);
58 for (label i = 0; i < n; i++)
63 // fullStaticHash is really slow
64 // give it lots of slots to help
65 StaticHashTable<nil, label, Hash<label> > emptyStaticHash;
66 StaticHashTable<nil, label, Hash<label> > fullStaticHash(100000);
67 for (label i = 0; i < n; i++)
69 fullStaticHash.insert(i, nil());
72 emptyHash.printInfo(Info);
73 fullHash.printInfo(Info);
74 emptyStaticHash.printInfo(Info);
75 fullStaticHash.printInfo(Info);
80 for (label iter = 0; iter < nIters; ++iter)
86 Info<< "resize/shrink/resize:" << timer.cpuTimeIncrement() << " s\n\n";
88 // set every other bit on:
89 Info<< "set every other bit on and count\n";
90 packed.storage() = 0xAAAAAAAAu;
94 for (label iter = 0; iter < nIters; ++iter)
101 Info<< "Counting brute-force:" << timer.cpuTimeIncrement()
103 Info<< " sum " << sum << endl;
108 for (label iter = 0; iter < nIters; ++iter)
110 sum += packed.count();
112 Info<< "Counting via count():" << timer.cpuTimeIncrement()
114 Info<< " sum " << sum << endl;
119 for (label iter = 0; iter < nIters; ++iter)
126 Info<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << endl;
127 Info<< " sum " << sum << endl;
135 for (label iter = 0; iter < nIters; ++iter)
137 for(unsigned int i = 0; i < stlVector.size(); i++)
142 Info<< "Reading stl:" << timer.cpuTimeIncrement() << " s" << endl;
143 Info<< " sum " << sum << endl;
148 for (label iter = 0; iter < nIters; ++iter)
155 Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << endl;
156 Info<< " sum " << sum << endl;
161 for (label iter = 0; iter < nIters; ++iter)
165 sum += packed.get(i);
168 Info<< "Reading packed using get:" << timer.cpuTimeIncrement()
170 Info<< " sum " << sum << endl;
175 for (label iter = 0; iter < nIters; ++iter)
182 Info<< "Reading packed using reference:" << timer.cpuTimeIncrement()
184 Info<< " sum " << sum << endl;
189 for (label iter = 0; iter < nIters; ++iter)
193 PackedBoolList::iterator it = packed.begin();
201 Info<< "Reading packed using iterator:" << timer.cpuTimeIncrement()
203 Info<< " sum " << sum << endl;
208 for (label iter = 0; iter < nIters; ++iter)
212 PackedBoolList::const_iterator cit = packed.cbegin();
213 cit != packed.cend();
220 Info<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement()
222 Info<< " sum " << sum << endl;
227 for (label iter = 0; iter < nIters; ++iter)
231 sum += emptyHash.found(i);
234 Info<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement()
236 Info<< " sum " << sum << endl;
241 for (label iter = 0; iter < nIters; ++iter)
245 sum += fullHash.found(i);
248 Info<< "Reading full labelHashSet:" << timer.cpuTimeIncrement()
250 Info<< " sum " << sum << endl;
253 // Read empty static hash
255 for (label iter = 0; iter < nIters; ++iter)
259 sum += emptyStaticHash.found(i);
262 Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement()
264 Info<< " sum " << sum << endl;
267 // we can skip this test - it is usually quite slow
268 // Read full static hash
270 for (label iter = 0; iter < nIters; ++iter)
274 sum += fullStaticHash.found(i);
277 Info<< "Reading full StaticHash:" << timer.cpuTimeIncrement()
279 Info<< " sum " << sum << endl;
282 Info<< "Starting write tests" << endl;
289 for (label iter = 0; iter < nIters; ++iter)
291 for (unsigned int i = 0; i < stlVector.size(); i++)
296 Info<< "Writing stl:" << timer.cpuTimeIncrement() << " s" << endl;
299 for (label iter = 0; iter < nIters; ++iter)
306 Info<< "Writing unpacked:" << timer.cpuTimeIncrement() << " s" << endl;
310 for (label iter = 0; iter < nIters; ++iter)
317 Info<< "Writing packed using reference:" << timer.cpuTimeIncrement()
322 for (label iter = 0; iter < nIters; ++iter)
329 Info<< "Writing packed using set:" << timer.cpuTimeIncrement()
334 for (label iter = 0; iter < nIters; ++iter)
338 PackedBoolList::iterator it = packed.begin();
346 Info<< "Writing packed using iterator:" << timer.cpuTimeIncrement()
351 for (label iter = 0; iter < nIters; ++iter)
355 Info<< "Writing packed uniform 0:" << timer.cpuTimeIncrement()
360 for (label iter = 0; iter < nIters; ++iter)
364 Info<< "Writing packed uniform 1:" << timer.cpuTimeIncrement()
368 PackedList<3> oddPacked(n, 3);
371 for (label iter = 0; iter < nIters; ++iter)
375 Info<< "Writing packed<3> uniform 0:" << timer.cpuTimeIncrement()
380 for (label iter = 0; iter < nIters; ++iter)
384 Info<< "Writing packed<3> uniform 1:" << timer.cpuTimeIncrement()
388 Info << "End\n" << endl;
394 // ************************************************************************* //