mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: compilation of some unit tests
This commit is contained in:
@ -35,12 +35,20 @@ Description
|
|||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Ostream& printInfo(Ostream& os, const HashTable<T, T, Hash<T>>& ht)
|
||||||
|
{
|
||||||
|
os << " (size " << ht.size() << " capacity " << ht.capacity() << ") ";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
// Main program:
|
// Main program:
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const label nLoops = 30;
|
const label nLoops = 300;
|
||||||
const label nBase = 100000;
|
const label nBase = 100000;
|
||||||
const label nSize = nLoops * nBase;
|
const label nSize = nLoops * nBase;
|
||||||
|
|
||||||
@ -52,17 +60,18 @@ int main(int argc, char *argv[])
|
|||||||
// StaticHashTable<label, label, Hash<label>> map(2 * nSize);
|
// StaticHashTable<label, label, Hash<label>> map(2 * nSize);
|
||||||
HashTable<label, label, Hash<label>> map(2 * nSize);
|
HashTable<label, label, Hash<label>> map(2 * nSize);
|
||||||
|
|
||||||
Info<< "Constructed map of size: " << nSize
|
Info<< "Constructed map of size: " << nSize;
|
||||||
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
|
printInfo(Info, map);
|
||||||
<< " " << timer.cpuTimeIncrement() << " s\n\n";
|
Info<< timer.cpuTimeIncrement() << " s\n\n";
|
||||||
|
|
||||||
for (label i = 0; i < nSize; i++)
|
for (label i = 0; i < nSize; i++)
|
||||||
{
|
{
|
||||||
map.insert(i, i);
|
map.insert(i, i);
|
||||||
}
|
}
|
||||||
Info<< "Inserted " << nSize << " elements"
|
|
||||||
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
|
Info<< "Inserted " << nSize << " elements";
|
||||||
<< timer.cpuTimeIncrement() << " s\n";
|
printInfo(Info, map);
|
||||||
|
Info<< timer.cpuTimeIncrement() << " s\n\n";
|
||||||
|
|
||||||
label elemI = 0;
|
label elemI = 0;
|
||||||
for (label iLoop = 0; iLoop < nLoops; iLoop++)
|
for (label iLoop = 0; iLoop < nLoops; iLoop++)
|
||||||
@ -72,12 +81,14 @@ int main(int argc, char *argv[])
|
|||||||
map.erase(elemI++);
|
map.erase(elemI++);
|
||||||
}
|
}
|
||||||
|
|
||||||
map.shrink();
|
// map.shrink();
|
||||||
Info<< "loop " << iLoop << " - Erased " << nBase << " elements"
|
Info<< "loop " << iLoop << " - Erased " << nBase << " elements";
|
||||||
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
|
printInfo(Info, map);
|
||||||
<< timer.cpuTimeIncrement() << " s\n";
|
Info << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Info<< timer.cpuTimeIncrement() << " s\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
EXE_INC = ${c++LESSWARN}
|
||||||
|
|
||||||
|
/* EXE_LIBS = */
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
EXE_INC = ${c++LESSWARN}
|
||||||
|
|
||||||
|
/* EXE_LIBS = */
|
||||||
|
|||||||
@ -34,9 +34,25 @@ Description
|
|||||||
#include "StaticHashTable.H"
|
#include "StaticHashTable.H"
|
||||||
#include "cpuTime.H"
|
#include "cpuTime.H"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
|
#undef TEST_STATIC_HASH
|
||||||
|
#undef TEST_STD_BOOLLIST
|
||||||
|
#undef TEST_STD_UNORDERED_SET
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void printInfo(const std::unordered_set<T, Foam::Hash<T>>& 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 n = 1000000;
|
||||||
const label nIters = 1000;
|
const label nIters = 1000;
|
||||||
|
|
||||||
unsigned int sum = 0;
|
unsigned long sum = 0;
|
||||||
|
|
||||||
PackedBoolList packed(n, 1);
|
PackedBoolList packed(n, 1);
|
||||||
boolList unpacked(n, true);
|
boolList unpacked(n, true);
|
||||||
std::vector<bool> stlVector(n, true);
|
|
||||||
|
#ifdef TEST_STD_BOOLLIST
|
||||||
|
std::vector<bool> stdBoolList(n, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cpuTime timer;
|
||||||
|
|
||||||
labelHashSet emptyHash;
|
labelHashSet emptyHash;
|
||||||
labelHashSet fullHash(1024);
|
labelHashSet fullHash(1024);
|
||||||
@ -60,6 +81,11 @@ int main(int argc, char *argv[])
|
|||||||
fullHash.insert(i);
|
fullHash.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Info<< "populated labelHashSet in "
|
||||||
|
<< timer.cpuTimeIncrement() << " s\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef TEST_STATIC_HASH
|
||||||
// fullStaticHash is really slow
|
// fullStaticHash is really slow
|
||||||
// give it lots of slots to help
|
// give it lots of slots to help
|
||||||
StaticHashTable<nil, label, Hash<label>> emptyStaticHash;
|
StaticHashTable<nil, label, Hash<label>> emptyStaticHash;
|
||||||
@ -68,14 +94,32 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
fullStaticHash.insert(i, nil());
|
fullStaticHash.insert(i, nil());
|
||||||
}
|
}
|
||||||
|
Info<< "populated StaticHashTable in "
|
||||||
|
<< timer.cpuTimeIncrement() << " s\n\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TEST_STD_UNORDERED_SET
|
||||||
|
std::unordered_set<label, Foam::Hash<label>> emptyStdHash;
|
||||||
|
std::unordered_set<label, Foam::Hash<label>> 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);
|
emptyHash.printInfo(Info);
|
||||||
fullHash.printInfo(Info);
|
fullHash.printInfo(Info);
|
||||||
|
#ifdef TEST_STATIC_HASH
|
||||||
emptyStaticHash.printInfo(Info);
|
emptyStaticHash.printInfo(Info);
|
||||||
fullStaticHash.printInfo(Info);
|
fullStaticHash.printInfo(Info);
|
||||||
|
#endif
|
||||||
|
#ifdef TEST_STD_UNORDERED_SET
|
||||||
cpuTime timer;
|
printInfo(emptyStdHash);
|
||||||
|
printInfo(fullStdHash);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (label iter = 0; iter < nIters; ++iter)
|
for (label iter = 0; iter < nIters; ++iter)
|
||||||
{
|
{
|
||||||
@ -104,9 +148,11 @@ int main(int argc, char *argv[])
|
|||||||
sum += packed[i];
|
sum += packed[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Counting brute-force:" << timer.cpuTimeIncrement()
|
|
||||||
|
std::cout
|
||||||
|
<< "Counting brute-force:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Count packed
|
// Count packed
|
||||||
@ -115,9 +161,11 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
sum += packed.count();
|
sum += packed.count();
|
||||||
}
|
}
|
||||||
Info<< "Counting via count():" << timer.cpuTimeIncrement()
|
|
||||||
|
std::cout
|
||||||
|
<< "Counting via count():" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Dummy addition
|
// Dummy addition
|
||||||
@ -129,25 +177,29 @@ int main(int argc, char *argv[])
|
|||||||
sum += i + 1;
|
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
|
// Read
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#ifdef TEST_STD_BOOLLIST
|
||||||
// Read stl
|
// Read stl
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (label iter = 0; iter < nIters; ++iter)
|
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
|
std::cout
|
||||||
<< " sum " << sum << endl;
|
<< "Reading stdBoolList:" << timer.cpuTimeIncrement() << " s" << nl
|
||||||
|
<< " sum " << sum << nl;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Read unpacked
|
// Read unpacked
|
||||||
sum = 0;
|
sum = 0;
|
||||||
@ -158,8 +210,9 @@ int main(int argc, char *argv[])
|
|||||||
sum += unpacked[i];
|
sum += unpacked[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << nl
|
std::cout
|
||||||
<< " sum " << sum << endl;
|
<< "Reading unpacked:" << timer.cpuTimeIncrement() << " s" << nl
|
||||||
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Read packed
|
// Read packed
|
||||||
@ -171,9 +224,10 @@ int main(int argc, char *argv[])
|
|||||||
sum += packed.get(i);
|
sum += packed.get(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading packed using get:" << timer.cpuTimeIncrement()
|
std::cout
|
||||||
|
<< "Reading packed using get:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Read packed
|
// Read packed
|
||||||
@ -185,9 +239,10 @@ int main(int argc, char *argv[])
|
|||||||
sum += packed[i];
|
sum += packed[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading packed using reference:" << timer.cpuTimeIncrement()
|
std::cout
|
||||||
|
<< "Reading packed using reference:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Read via iterator
|
// Read via iterator
|
||||||
@ -199,9 +254,10 @@ int main(int argc, char *argv[])
|
|||||||
sum += it;
|
sum += it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading packed using iterator:" << timer.cpuTimeIncrement()
|
std::cout
|
||||||
|
<< "Reading packed using iterator:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Read via iterator
|
// Read via iterator
|
||||||
@ -213,9 +269,10 @@ int main(int argc, char *argv[])
|
|||||||
sum += cit();
|
sum += cit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement()
|
std::cout
|
||||||
|
<< "Reading packed using const_iterator():" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Read empty hash
|
// Read empty hash
|
||||||
@ -227,9 +284,10 @@ int main(int argc, char *argv[])
|
|||||||
sum += emptyHash.found(i);
|
sum += emptyHash.found(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement()
|
std::cout
|
||||||
|
<< "Reading empty labelHashSet:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Read full hash
|
// Read full hash
|
||||||
@ -241,12 +299,14 @@ int main(int argc, char *argv[])
|
|||||||
sum += fullHash.found(i);
|
sum += fullHash.found(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading full labelHashSet:" << timer.cpuTimeIncrement()
|
std::cout
|
||||||
|
<< "Reading full labelHashSet:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
|
|
||||||
// Read empty static hash
|
#ifdef TEST_STATIC_HASH
|
||||||
|
// Read empty StaticHashTable
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (label iter = 0; iter < nIters; ++iter)
|
for (label iter = 0; iter < nIters; ++iter)
|
||||||
{
|
{
|
||||||
@ -255,13 +315,12 @@ int main(int argc, char *argv[])
|
|||||||
sum += emptyStaticHash.found(i);
|
sum += emptyStaticHash.found(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading empty StaticHash:" << timer.cpuTimeIncrement()
|
std::cout
|
||||||
|
<< "Reading empty StaticHash:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
|
|
||||||
#if 0
|
// Read full StaticHashTable
|
||||||
// we can skip this test - it is usually quite slow
|
|
||||||
// Read full static hash
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (label iter = 0; iter < nIters; ++iter)
|
for (label iter = 0; iter < nIters; ++iter)
|
||||||
{
|
{
|
||||||
@ -270,26 +329,60 @@ int main(int argc, char *argv[])
|
|||||||
sum += fullStaticHash.found(i);
|
sum += fullStaticHash.found(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Reading full StaticHash:" << timer.cpuTimeIncrement()
|
std::cout
|
||||||
|
<< "Reading full StaticHash:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << nl
|
<< " s" << nl
|
||||||
<< " sum " << sum << endl;
|
<< " sum " << sum << nl;
|
||||||
#endif
|
#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
|
||||||
//
|
//
|
||||||
|
|
||||||
// Write stl
|
#ifdef TEST_STD_BOOLLIST
|
||||||
|
// Read stl
|
||||||
for (label iter = 0; iter < nIters; ++iter)
|
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
|
// Write unpacked
|
||||||
for (label iter = 0; iter < nIters; ++iter)
|
for (label iter = 0; iter < nIters; ++iter)
|
||||||
@ -299,7 +392,7 @@ int main(int argc, char *argv[])
|
|||||||
unpacked[i] = true;
|
unpacked[i] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Writing unpacked:" << timer.cpuTimeIncrement() << " s" << endl;
|
Info<< "Writing unpacked:" << timer.cpuTimeIncrement() << " s" << nl;
|
||||||
|
|
||||||
|
|
||||||
// Write packed
|
// Write packed
|
||||||
@ -311,7 +404,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Writing packed using reference:" << timer.cpuTimeIncrement()
|
Info<< "Writing packed using reference:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << endl;
|
<< " s" << nl;
|
||||||
|
|
||||||
|
|
||||||
// Write packed
|
// Write packed
|
||||||
@ -323,7 +416,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Writing packed using set:" << timer.cpuTimeIncrement()
|
Info<< "Writing packed using set:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << endl;
|
<< " s" << nl;
|
||||||
|
|
||||||
// Write packed
|
// Write packed
|
||||||
for (label iter = 0; iter < nIters; ++iter)
|
for (label iter = 0; iter < nIters; ++iter)
|
||||||
@ -334,7 +427,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info<< "Writing packed using iterator:" << timer.cpuTimeIncrement()
|
Info<< "Writing packed using iterator:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << endl;
|
<< " s" << nl;
|
||||||
|
|
||||||
|
|
||||||
// Write packed
|
// Write packed
|
||||||
@ -343,7 +436,7 @@ int main(int argc, char *argv[])
|
|||||||
packed = 0;
|
packed = 0;
|
||||||
}
|
}
|
||||||
Info<< "Writing packed uniform 0:" << timer.cpuTimeIncrement()
|
Info<< "Writing packed uniform 0:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << endl;
|
<< " s" << nl;
|
||||||
|
|
||||||
|
|
||||||
// Write packed
|
// Write packed
|
||||||
@ -352,7 +445,7 @@ int main(int argc, char *argv[])
|
|||||||
packed = 1;
|
packed = 1;
|
||||||
}
|
}
|
||||||
Info<< "Writing packed uniform 1:" << timer.cpuTimeIncrement()
|
Info<< "Writing packed uniform 1:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << endl;
|
<< " s" << nl;
|
||||||
|
|
||||||
|
|
||||||
PackedList<3> oddPacked(n, 3);
|
PackedList<3> oddPacked(n, 3);
|
||||||
@ -363,7 +456,7 @@ int main(int argc, char *argv[])
|
|||||||
packed = 0;
|
packed = 0;
|
||||||
}
|
}
|
||||||
Info<< "Writing packed<3> uniform 0:" << timer.cpuTimeIncrement()
|
Info<< "Writing packed<3> uniform 0:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << endl;
|
<< " s" << nl;
|
||||||
|
|
||||||
|
|
||||||
// Write packed
|
// Write packed
|
||||||
@ -372,7 +465,7 @@ int main(int argc, char *argv[])
|
|||||||
packed = 1;
|
packed = 1;
|
||||||
}
|
}
|
||||||
Info<< "Writing packed<3> uniform 1:" << timer.cpuTimeIncrement()
|
Info<< "Writing packed<3> uniform 1:" << timer.cpuTimeIncrement()
|
||||||
<< " s" << endl;
|
<< " s" << nl;
|
||||||
|
|
||||||
|
|
||||||
Info<< "End\n" << endl;
|
Info<< "End\n" << endl;
|
||||||
|
|||||||
@ -28,11 +28,7 @@ Description
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "boolList.H"
|
|
||||||
#include "HashSet.H"
|
|
||||||
#include "StaticHashTable.H"
|
|
||||||
#include "cpuTime.H"
|
#include "cpuTime.H"
|
||||||
#include <vector>
|
|
||||||
#include "PackedBoolList.H"
|
#include "PackedBoolList.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
@ -44,24 +40,29 @@ using namespace Foam;
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
const label nLoop = 5;
|
||||||
const label n = 100000000;
|
const label n = 100000000;
|
||||||
const label nReport = 1000000;
|
// const label nReport = 1000000;
|
||||||
|
|
||||||
cpuTime timer;
|
cpuTime timer;
|
||||||
|
|
||||||
// test inserts
|
// test inserts
|
||||||
// PackedBoolList
|
|
||||||
PackedBoolList packed;
|
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"
|
// if ((i % nReport) == 0 && i)
|
||||||
<<endl;
|
// {
|
||||||
|
// Info<< "." << flush;
|
||||||
|
// }
|
||||||
|
packed[i] = 1;
|
||||||
|
// Make compiler do something else too
|
||||||
|
packed[i/2] = 0;
|
||||||
}
|
}
|
||||||
packed[i] = 1;
|
|
||||||
}
|
}
|
||||||
Info<< "insert test: " << n << " elements in "
|
Info<< nl
|
||||||
|
<< "insert test: " << nLoop << "*" << n << " elements in "
|
||||||
<< timer.cpuTimeIncrement() << " s\n\n";
|
<< timer.cpuTimeIncrement() << " s\n\n";
|
||||||
|
|
||||||
Info << "\nEnd\n" << endl;
|
Info << "\nEnd\n" << endl;
|
||||||
|
|||||||
@ -28,6 +28,7 @@ Description
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "uLabel.H"
|
#include "uLabel.H"
|
||||||
|
#include "boolList.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "PackedBoolList.H"
|
#include "PackedBoolList.H"
|
||||||
#include "StringStream.H"
|
#include "StringStream.H"
|
||||||
@ -146,17 +147,16 @@ int main(int argc, char *argv[])
|
|||||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||||
|
|
||||||
Info<< "\nassign from labelList\n";
|
Info<< "\nassign from labelList\n";
|
||||||
list4 = labelList
|
list4 = labelList{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
|
||||||
(
|
|
||||||
IStringStream
|
|
||||||
(
|
|
||||||
"(0 1 2 3 12 13 14 19 20 21)"
|
|
||||||
)()
|
|
||||||
);
|
|
||||||
|
|
||||||
list4.printInfo(Info, true);
|
list4.printInfo(Info, true);
|
||||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||||
|
|
||||||
|
// Not yet:
|
||||||
|
// PackedBoolList list5{0, 1, 2, 3, 12, 13, 14, 19, 20, 21};
|
||||||
|
// list5.printInfo(Info, true);
|
||||||
|
// Info<< list5 << " indices: " << list5.used()() << nl;
|
||||||
|
|
||||||
Info<< "\nassign from indices\n";
|
Info<< "\nassign from indices\n";
|
||||||
list4.read
|
list4.read
|
||||||
(
|
(
|
||||||
@ -170,13 +170,13 @@ int main(int argc, char *argv[])
|
|||||||
list4.printInfo(Info, true);
|
list4.printInfo(Info, true);
|
||||||
Info<< list4 << " indices: " << list4.used()() << nl;
|
Info<< list4 << " indices: " << list4.used()() << nl;
|
||||||
|
|
||||||
List<bool> boolLst(list4.size());
|
boolList bools(list4.size());
|
||||||
forAll(list4, i)
|
forAll(list4, i)
|
||||||
{
|
{
|
||||||
boolLst[i] = list4[i];
|
bools[i] = list4[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< "List<bool>: " << boolLst << nl;
|
Info<< "boolList: " << bools << nl;
|
||||||
|
|
||||||
// check roundabout assignments
|
// check roundabout assignments
|
||||||
PackedList<2> pl2
|
PackedList<2> pl2
|
||||||
|
|||||||
Reference in New Issue
Block a user