Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
OpenFOAM-plus
Commits
aa66d3a5
Commit
aa66d3a5
authored
Oct 26, 2017
by
Mark Olesen
Browse files
STYLE: compilation of some unit tests
parent
92a22882
Changes
6
Hide whitespace changes
Inline
Side-by-side
applications/test/HashTable3/Test-HashTable3.C
View file @
aa66d3a5
...
...
@@ -35,12 +35,20 @@ Description
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:
int
main
(
int
argc
,
char
*
argv
[])
{
const
label
nLoops
=
30
;
const
label
nLoops
=
30
0
;
const
label
nBase
=
100000
;
const
label
nSize
=
nLoops
*
nBase
;
...
...
@@ -52,17 +60,18 @@ int main(int argc, char *argv[])
// StaticHashTable<label, label, Hash<label>> map(2 * nSize);
HashTable
<
label
,
label
,
Hash
<
label
>>
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
;
}
...
...
applications/test/Hashing/Make/options
View file @
aa66d3a5
EXE_INC = ${c++LESSWARN}
/* EXE_LIBS = */
applications/test/HashingSpeed/Make/options
View file @
aa66d3a5
EXE_INC = ${c++LESSWARN}
/* EXE_LIBS = */
applications/test/PackedList2/Test-PackedList2.C
View file @
aa66d3a5
...
...
@@ -34,9 +34,25 @@ Description
#include "StaticHashTable.H"
#include "cpuTime.H"
#include <vector>
#include <unordered_set>
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
nIters
=
1000
;
unsigned
int
sum
=
0
;
unsigned
long
sum
=
0
;
PackedBoolList
packed
(
n
,
1
);
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
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
<
nil
,
label
,
Hash
<
label
>>
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
<
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
);
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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
// 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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
// 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
<
st
lVector
.
size
();
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
st
dBoolList
.
size
();
i
++
)
{
sum
+=
st
lVector
[
i
];
sum
+=
st
dBoolList
[
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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
// 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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
// 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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
// 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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
// 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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
// 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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
// 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
<<
end
l
;
<<
" sum "
<<
sum
<<
n
l
;
#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 <<
end
l;
#endif
<<
" sum "
<<
sum
<<
n
l
;
#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
<
st
lVector
.
size
();
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
st
dBoolList
.
size
();
i
++
)
{
st
lVector
[
i
]
=
true
;
st
dBoolList
[
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"
<<
end
l
;
Info
<<
"Writing unpacked:"
<<
timer
.
cpuTimeIncrement
()
<<
" s"
<<
n
l
;
// Write packed
...
...
@@ -311,7 +404,7 @@ int main(int argc, char *argv[])
}
}
Info
<<
"Writing packed using reference:"
<<
timer
.
cpuTimeIncrement
()
<<
" s"
<<
end
l
;
<<
" s"
<<
n
l
;
// Write packed
...
...
@@ -323,7 +416,7 @@ int main(int argc, char *argv[])
}
}
Info
<<
"Writing packed using set:"
<<
timer
.
cpuTimeIncrement
()
<<
" s"
<<
end
l
;
<<
" s"
<<
n
l
;
// 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"
<<
end
l
;
<<
" s"
<<
n
l
;
// Write packed
...
...
@@ -343,7 +436,7 @@ int main(int argc, char *argv[])
packed
=
0
;
}
Info
<<
"Writing packed uniform 0:"
<<
timer
.
cpuTimeIncrement
()
<<
" s"
<<
end
l
;
<<
" s"
<<
n
l
;
// Write packed
...
...
@@ -352,7 +445,7 @@ int main(int argc, char *argv[])
packed
=
1
;
}
Info
<<
"Writing packed uniform 1:"
<<
timer
.
cpuTimeIncrement
()
<<
" s"
<<
end
l
;
<<
" s"
<<
n
l
;
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"
<<
end
l
;
<<
" s"
<<
n
l
;
// Write packed
...
...
@@ -372,7 +465,7 @@ int main(int argc, char *argv[])
packed
=
1
;
}
Info
<<
"Writing packed<3> uniform 1:"
<<
timer
.
cpuTimeIncrement
()
<<
" s"
<<
end
l
;
<<
" s"
<<
n
l
;
Info
<<
"End
\n
"
<<
endl
;
...
...
applications/test/PackedList3/Test-PackedList3.C
View file @
aa66d3a5
...
...
@@ -28,11 +28,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "boolList.H"
#include "HashSet.H"
#include "StaticHashTable.H"
#include "cpuTime.H"
#include <vector>
#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
i
loop
=
0
;
i
loop
<
nLoop
;
++
iloop
)
{
if
((
i
%
nReport
)
==
0
&&
i
)
for
(
label
i
=
0
;
i
<
n
;
++
i
)
{
Info
<<
"i:"
<<
i
<<
" in "
<<
timer
.
cpuTimeIncrement
()
<<
" s"
<<
endl
;
// if ((i % nReport) == 0 && i)
// {
// 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
"
;
Info
<<
"
\n
End
\n
"
<<
endl
;
...
...
applications/test/PackedList4/Test-PackedList4.C
View file @
aa66d3a5
...
...
@@ -28,6 +28,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "uLabel.H"
#include "boolList.H"
#include "IOstreams.H"
#include "PackedBoolList.H"
#include "StringStream.H"
...
...
@@ -146,17 +147,16 @@ int main(int argc, char *argv[])
Info
<<
list4
<<
" indices: "
<<
list4
.
used
()()
<<
nl
;
Info
<<
"
\n
assign from labelList
\n
"
;
list4
=
labelList
(
IStringStream
(
"(0 1 2 3 12 13 14 19 20 21)"
)()
);
list4
=
labelList
{
0
,
1
,
2
,
3
,
12
,
13
,
14
,
19
,
20
,
21
};
list4
.
printInfo
(
Info
,
true
);
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
<<
"
\n
assign from indices
\n
"
;
list4
.
read
(
...
...
@@ -170,13 +170,13 @@ int main(int argc, char *argv[])
list4
.
printInfo
(
Info
,
true
);
Info
<<
list4
<<
" indices: "
<<
list4
.
used
()()
<<
nl
;
List
<
bool
>
bool
Lst
(
list4
.
size
());
bool
List
bool
s
(
list4
.
size
());
forAll
(
list4
,
i
)
{
bool
Lst
[
i
]
=
list4
[
i
];
bool
s
[
i
]
=
list4
[
i
];
}
Info
<<
"List
<bool>
: "
<<
bool
Lst
<<
nl
;
Info
<<
"
bool
List: "
<<
bool
s
<<
nl
;
// check roundabout assignments
PackedList
<
2
>
pl2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment