diff --git a/applications/test/HashTable3/Test-HashTable3.C b/applications/test/HashTable3/Test-HashTable3.C index 7184d30574..39c882d6eb 100644 --- a/applications/test/HashTable3/Test-HashTable3.C +++ b/applications/test/HashTable3/Test-HashTable3.C @@ -35,12 +35,20 @@ Description using namespace Foam; +template +Ostream& printInfo(Ostream& os, const HashTable>& ht) +{ + os << " (size " << ht.size() << " capacity " << ht.capacity() << ") "; + return os; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: int main(int argc, char *argv[]) { - const label nLoops = 30; + const label nLoops = 300; const label nBase = 100000; const label nSize = nLoops * nBase; @@ -52,17 +60,18 @@ int main(int argc, char *argv[]) // StaticHashTable> map(2 * nSize); HashTable> map(2 * nSize); - Info<< "Constructed map of size: " << nSize - << " (size " << map.size() << " capacity " << map.capacity() << ") " - << " " << timer.cpuTimeIncrement() << " s\n\n"; + Info<< "Constructed map of size: " << nSize; + printInfo(Info, map); + Info<< 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"; + + Info<< "Inserted " << nSize << " elements"; + printInfo(Info, map); + Info<< timer.cpuTimeIncrement() << " s\n\n"; label elemI = 0; for (label iLoop = 0; iLoop < nLoops; iLoop++) @@ -72,12 +81,14 @@ int main(int argc, char *argv[]) map.erase(elemI++); } - map.shrink(); - Info<< "loop " << iLoop << " - Erased " << nBase << " elements" - << " (size " << map.size() << " capacity " << map.capacity() << ") " - << timer.cpuTimeIncrement() << " s\n"; + // map.shrink(); + Info<< "loop " << iLoop << " - Erased " << nBase << " elements"; + printInfo(Info, map); + Info << nl; } + Info<< timer.cpuTimeIncrement() << " s\n"; + return 0; } diff --git a/applications/test/Hashing/Make/options b/applications/test/Hashing/Make/options index e69de29bb2..7dba39797a 100644 --- a/applications/test/Hashing/Make/options +++ b/applications/test/Hashing/Make/options @@ -0,0 +1,3 @@ +EXE_INC = ${c++LESSWARN} + +/* EXE_LIBS = */ diff --git a/applications/test/HashingSpeed/Make/options b/applications/test/HashingSpeed/Make/options index e69de29bb2..7dba39797a 100644 --- a/applications/test/HashingSpeed/Make/options +++ b/applications/test/HashingSpeed/Make/options @@ -0,0 +1,3 @@ +EXE_INC = ${c++LESSWARN} + +/* EXE_LIBS = */ diff --git a/applications/test/PackedList2/Test-PackedList2.C b/applications/test/PackedList2/Test-PackedList2.C index ce9b15ed51..ad1df378de 100644 --- a/applications/test/PackedList2/Test-PackedList2.C +++ b/applications/test/PackedList2/Test-PackedList2.C @@ -34,9 +34,25 @@ Description #include "StaticHashTable.H" #include "cpuTime.H" #include +#include using namespace Foam; +#undef TEST_STATIC_HASH +#undef TEST_STD_BOOLLIST +#undef TEST_STD_UNORDERED_SET + +template +void printInfo(const std::unordered_set>& ht) +{ + Info<<"std::unordered_set elements:" + << ht.size() + << " buckets:" << ht.bucket_count() + << " load_factor: " << ht.load_factor() + << nl; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,11 +63,16 @@ int main(int argc, char *argv[]) const label n = 1000000; const label nIters = 1000; - unsigned int sum = 0; + unsigned long sum = 0; PackedBoolList packed(n, 1); boolList unpacked(n, true); - std::vector stlVector(n, true); + + #ifdef TEST_STD_BOOLLIST + std::vector stdBoolList(n, true); + #endif + + cpuTime timer; labelHashSet emptyHash; labelHashSet fullHash(1024); @@ -60,6 +81,11 @@ int main(int argc, char *argv[]) fullHash.insert(i); } + Info<< "populated labelHashSet in " + << timer.cpuTimeIncrement() << " s\n\n"; + + + #ifdef TEST_STATIC_HASH // fullStaticHash is really slow // give it lots of slots to help StaticHashTable> emptyStaticHash; @@ -68,14 +94,32 @@ int main(int argc, char *argv[]) { fullStaticHash.insert(i, nil()); } + Info<< "populated StaticHashTable in " + << timer.cpuTimeIncrement() << " s\n\n"; + #endif + + #ifdef TEST_STD_UNORDERED_SET + std::unordered_set> emptyStdHash; + std::unordered_set> fullStdHash; + fullStdHash.reserve(1024); + for (label i = 0; i < n; i++) + { + fullStdHash.insert(i); + } + Info<< "populated unordered_set in " + << timer.cpuTimeIncrement() << " s\n\n"; + #endif emptyHash.printInfo(Info); fullHash.printInfo(Info); + #ifdef TEST_STATIC_HASH emptyStaticHash.printInfo(Info); fullStaticHash.printInfo(Info); - - - cpuTime timer; + #endif + #ifdef TEST_STD_UNORDERED_SET + printInfo(emptyStdHash); + printInfo(fullStdHash); + #endif for (label iter = 0; iter < nIters; ++iter) { @@ -104,9 +148,11 @@ int main(int argc, char *argv[]) sum += packed[i]; } } - Info<< "Counting brute-force:" << timer.cpuTimeIncrement() + + std::cout + << "Counting brute-force:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; // Count packed @@ -115,9 +161,11 @@ int main(int argc, char *argv[]) { sum += packed.count(); } - Info<< "Counting via count():" << timer.cpuTimeIncrement() + + std::cout + << "Counting via count():" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; // Dummy addition @@ -129,25 +177,29 @@ int main(int argc, char *argv[]) sum += i + 1; } } - Info<< "Dummy loop:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << " (sum is meaningless)" << endl; + + std::cout + << "Dummy loop:" << timer.cpuTimeIncrement() << " s" << nl + << " sum " << sum << " (sum is meaningless)" << nl; // // Read // + #ifdef TEST_STD_BOOLLIST // Read stl sum = 0; for (label iter = 0; iter < nIters; ++iter) { - for (unsigned int i = 0; i < stlVector.size(); i++) + for (unsigned int i = 0; i < stdBoolList.size(); i++) { - sum += stlVector[i]; + sum += stdBoolList[i]; } } - Info<< "Reading stl:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; - + std::cout + << "Reading stdBoolList:" << timer.cpuTimeIncrement() << " s" << nl + << " sum " << sum << nl; + #endif // Read unpacked sum = 0; @@ -158,8 +210,9 @@ int main(int argc, char *argv[]) sum += unpacked[i]; } } - Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + std::cout + << "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << nl + << " sum " << sum << nl; // Read packed @@ -171,9 +224,10 @@ int main(int argc, char *argv[]) sum += packed.get(i); } } - Info<< "Reading packed using get:" << timer.cpuTimeIncrement() + std::cout + << "Reading packed using get:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; // Read packed @@ -185,9 +239,10 @@ int main(int argc, char *argv[]) sum += packed[i]; } } - Info<< "Reading packed using reference:" << timer.cpuTimeIncrement() + std::cout + << "Reading packed using reference:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; // Read via iterator @@ -199,9 +254,10 @@ int main(int argc, char *argv[]) sum += it; } } - Info<< "Reading packed using iterator:" << timer.cpuTimeIncrement() + std::cout + << "Reading packed using iterator:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; // Read via iterator @@ -213,9 +269,10 @@ int main(int argc, char *argv[]) sum += cit(); } } - Info<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement() + std::cout + << "Reading packed using const_iterator():" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; // Read empty hash @@ -227,9 +284,10 @@ int main(int argc, char *argv[]) sum += emptyHash.found(i); } } - Info<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement() + std::cout + << "Reading empty labelHashSet:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; // Read full hash @@ -241,12 +299,14 @@ int main(int argc, char *argv[]) sum += fullHash.found(i); } } - Info<< "Reading full labelHashSet:" << timer.cpuTimeIncrement() + std::cout + << "Reading full labelHashSet:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; - // Read empty static hash + #ifdef TEST_STATIC_HASH + // Read empty StaticHashTable sum = 0; for (label iter = 0; iter < nIters; ++iter) { @@ -255,13 +315,12 @@ int main(int argc, char *argv[]) sum += emptyStaticHash.found(i); } } - Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement() + std::cout + << "Reading empty StaticHash:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; + << " sum " << sum << nl; -#if 0 - // we can skip this test - it is usually quite slow - // Read full static hash + // Read full StaticHashTable sum = 0; for (label iter = 0; iter < nIters; ++iter) { @@ -270,26 +329,60 @@ int main(int argc, char *argv[]) sum += fullStaticHash.found(i); } } - Info<< "Reading full StaticHash:" << timer.cpuTimeIncrement() + std::cout + << "Reading full StaticHash:" << timer.cpuTimeIncrement() << " s" << nl - << " sum " << sum << endl; -#endif + << " sum " << sum << nl; + #endif - Info<< "Starting write tests" << endl; + + #ifdef TEST_STD_UNORDERED_SET + // Read empty stl set + sum = 0; + for (label iter = 0; iter < nIters; ++iter) + { + forAll(unpacked, i) + { + sum += (emptyStdHash.find(i) != emptyStdHash.cend()); + } + } + std::cout + << "Reading empty std::unordered_set:" << timer.cpuTimeIncrement() + << " s" << nl + << " sum " << sum << nl; + + // Read full stl set + sum = 0; + for (label iter = 0; iter < nIters; ++iter) + { + forAll(unpacked, i) + { + sum += (fullStdHash.find(i) != fullStdHash.cend()); + } + } + std::cout + << "Reading full std::unordered_set:" << timer.cpuTimeIncrement() + << " s" << nl + << " sum " << sum << nl; + #endif + + Info<< "Starting write tests" << nl; // // Write // - // Write stl + #ifdef TEST_STD_BOOLLIST + // Read stl for (label iter = 0; iter < nIters; ++iter) { - for (unsigned int i = 0; i < stlVector.size(); i++) + for (unsigned int i = 0; i < stdBoolList.size(); i++) { - stlVector[i] = true; + stdBoolList[i] = true; } } - Info<< "Writing stl:" << timer.cpuTimeIncrement() << " s" << endl; + Info<< "Writing stdBoolList:" << timer.cpuTimeIncrement() << " s" << nl; + #endif // Write unpacked for (label iter = 0; iter < nIters; ++iter) @@ -299,7 +392,7 @@ int main(int argc, char *argv[]) unpacked[i] = true; } } - Info<< "Writing unpacked:" << timer.cpuTimeIncrement() << " s" << endl; + Info<< "Writing unpacked:" << timer.cpuTimeIncrement() << " s" << nl; // Write packed @@ -311,7 +404,7 @@ int main(int argc, char *argv[]) } } Info<< "Writing packed using reference:" << timer.cpuTimeIncrement() - << " s" << endl; + << " s" << nl; // Write packed @@ -323,7 +416,7 @@ int main(int argc, char *argv[]) } } Info<< "Writing packed using set:" << timer.cpuTimeIncrement() - << " s" << endl; + << " s" << nl; // Write packed for (label iter = 0; iter < nIters; ++iter) @@ -334,7 +427,7 @@ int main(int argc, char *argv[]) } } Info<< "Writing packed using iterator:" << timer.cpuTimeIncrement() - << " s" << endl; + << " s" << nl; // Write packed @@ -343,7 +436,7 @@ int main(int argc, char *argv[]) packed = 0; } Info<< "Writing packed uniform 0:" << timer.cpuTimeIncrement() - << " s" << endl; + << " s" << nl; // Write packed @@ -352,7 +445,7 @@ int main(int argc, char *argv[]) packed = 1; } Info<< "Writing packed uniform 1:" << timer.cpuTimeIncrement() - << " s" << endl; + << " s" << nl; PackedList<3> oddPacked(n, 3); @@ -363,7 +456,7 @@ int main(int argc, char *argv[]) packed = 0; } Info<< "Writing packed<3> uniform 0:" << timer.cpuTimeIncrement() - << " s" << endl; + << " s" << nl; // Write packed @@ -372,7 +465,7 @@ int main(int argc, char *argv[]) packed = 1; } Info<< "Writing packed<3> uniform 1:" << timer.cpuTimeIncrement() - << " s" << endl; + << " s" << nl; Info<< "End\n" << endl; diff --git a/applications/test/PackedList3/Test-PackedList3.C b/applications/test/PackedList3/Test-PackedList3.C index 0665363ebe..5add878925 100644 --- a/applications/test/PackedList3/Test-PackedList3.C +++ b/applications/test/PackedList3/Test-PackedList3.C @@ -28,11 +28,7 @@ Description \*---------------------------------------------------------------------------*/ #include "argList.H" -#include "boolList.H" -#include "HashSet.H" -#include "StaticHashTable.H" #include "cpuTime.H" -#include #include "PackedBoolList.H" using namespace Foam; @@ -44,24 +40,29 @@ using namespace Foam; int main(int argc, char *argv[]) { + const label nLoop = 5; const label n = 100000000; - const label nReport = 1000000; + // const label nReport = 1000000; cpuTime timer; // test inserts - // PackedBoolList PackedBoolList packed; - for (label i = 0; i < n; i++) + for (label iloop = 0; iloop < nLoop; ++iloop) { - if ((i % nReport) == 0 && i) + for (label i = 0; i < n; ++i) { - Info<< "i:" << i << " in " << timer.cpuTimeIncrement() << " s" - < boolLst(list4.size()); + boolList bools(list4.size()); forAll(list4, i) { - boolLst[i] = list4[i]; + bools[i] = list4[i]; } - Info<< "List: " << boolLst << nl; + Info<< "boolList: " << bools << nl; // check roundabout assignments PackedList<2> pl2