9 #include <fei_macros.hpp>
10 #include <fei_utils.hpp>
11 #include <test_utils/fei_test_utils.hpp>
12 #include <test_utils/test_benchmarks.hpp>
13 #include <snl_fei_Utils.hpp>
14 #include <fei_ctg_set.hpp>
15 #include <snl_fei_RaggedTable.hpp>
16 #include <snl_fei_RaggedTable_specialize.hpp>
17 #include <test_utils/HexBeam.hpp>
20 #define fei_file "test_benchmarks.cpp"
22 #include <fei_ErrMacros.hpp>
24 test_benchmarks::test_benchmarks(MPI_Comm comm)
29 test_benchmarks::~test_benchmarks()
33 template<
typename MAP_TYPE,
typename SET_TYPE>
34 double time_raggedtable_insert(
int len)
38 HexBeam hexcube(10, len, 1, HexBeam::OneD, 1, 0);
42 int numIndices = hexcube.numNodesPerElem();
44 int* indices =
new int[numIndices];
46 int first = hexcube.firstLocalElem();
48 for(
int n=0; n<hexcube.numLocalElems(); ++n) {
51 hexcube.getElemConnectivity(elem, indices);
53 table.
addIndices(numIndices, indices, numIndices, indices);
62 template<
typename MAP_TYPE,
typename SET_TYPE>
63 double benchmark_raggedtable()
68 double time_taken = time_raggedtable_insert<MAP_TYPE,SET_TYPE>(len);
69 while(time_taken < 1.0) {
71 time_taken = time_raggedtable_insert<MAP_TYPE,SET_TYPE>(len);
77 while(time_taken<5.0) {
78 time_taken += time_raggedtable_insert<MAP_TYPE,SET_TYPE>(len);
82 return((
double)(i*len)/time_taken);
85 void print_benchmark_banner()
89 FEI_COUT <<
" Benchmark name ";
93 FEI_COUT <<
"gold-copy";
95 FEI_COUT <<
" Result "<<FEI_ENDL;
98 FEI_COUT <<
" -----------------------";
100 FEI_COUT <<
"----- ";
102 FEI_COUT <<
"---------";
104 FEI_COUT <<
" ------ "<<FEI_ENDL;
107 void print_benchmark_line(
const char* name,
112 FEI_COUT.setf(IOS_FIXED, IOS_FLOATFIELD);
113 FEI_COUT.precision(1);
120 if (goldvalue < 0.0) FEI_COUT <<
"n/a";
121 else FEI_COUT << goldvalue;
123 FEI_COUT << passfail << FEI_ENDL;
126 std::string add_macro_values(
const char* name)
128 FEI_OSTRINGSTREAM osstr;
131 #if defined(FEI_PLATFORM) && defined(FEI_OPT_LEVEL)
132 osstr <<
"_" << FEI_PLATFORM <<
"_" << FEI_OPT_LEVEL;
134 osstr <<
"_unknown_unknown";
140 int test_benchmarks::runtests()
142 if (numProcs_ > 1)
return(0);
147 <<
" ***** Benchmarks pass if within 10% of 'gold-copy' *****"
148 <<FEI_ENDL<<FEI_ENDL;
150 #if defined(FEI_PLATFORM) && defined(FEI_OPT_LEVEL)
151 FEI_COUT <<
" FEI_PLATFORM: "<<FEI_PLATFORM
152 <<
", FEI_OPT_LEVEL: "<<FEI_OPT_LEVEL
153 <<FEI_ENDL<<FEI_ENDL;
154 FEI_COUT <<
" 'gold-copy' benchmark values will be searched for in ./fei_utest_timings.txt"<<FEI_ENDL;
157 FEI_COUT <<
" preprocessor macros FEI_PLATFORM and FEI_OPT_LEVEL aren't defined, so"<<FEI_ENDL;
158 FEI_COUT <<
" ./fei_utest_timings.txt will not be searched for 'gold-copy' benchmark values"<<FEI_ENDL<<FEI_ENDL;
172 int test_benchmarks::test1()
174 FEI_COUT <<
"Following group of benchmarks inserts integers into ragged tables"
175 <<
" (simulating"<<FEI_ENDL
176 <<
"matrix-graph construction) using various data structures."<<FEI_ENDL
177 <<
"A higher number is better, indicating more insertions"
178 <<
" in fixed amount of time." << FEI_ENDL<<FEI_ENDL;
180 print_benchmark_banner();
183 double value, goldvalue;
185 std::string testname;
187 value = benchmark_raggedtable<std::map<int,std::set<int>*>,std::set<int> >();
190 print_benchmark_line(
"std::map<std::set>", value, goldvalue, passfail.c_str());
192 testname = add_macro_values(
"std::map<fei::ctg_set>");
193 value = benchmark_raggedtable<std::map<int,fei::ctg_set<int>*>,
fei::ctg_set<int> >();
197 passfail = fei_test_utils::check_test_result(value, goldvalue, 10);
198 if (passfail !=
"passed") returnValue = -1;
205 print_benchmark_line(
"std::map<fei::ctg_set>", value, goldvalue, passfail.c_str());
209 testname = add_macro_values(
"snl_fei::MapContig<fei::ctg_set>");
210 value = benchmark_raggedtable<snl_fei::MapContig<fei::ctg_set<int>*>,
fei::ctg_set<int> >();
214 passfail = fei_test_utils::check_test_result(value, goldvalue, 10);
215 if (passfail !=
"passed") returnValue = -1;
222 print_benchmark_line(
"snl_fei::MapContig<fei::ctg_set>", value, goldvalue, passfail.c_str());
227 value = benchmark_raggedtable<FEI_HASH_MAP<int,FEI_HASH_SET<int>*>,FEI_HASH_SET<int> >();
230 print_benchmark_line(
"hash_map<hash_set>", value, goldvalue, passfail.c_str());
236 FEI_COUT << FEI_ENDL;
237 if (returnValue != 0) {
238 FEI_COUT <<
"at least 1 benchmark failed."<< FEI_ENDL << FEI_ENDL;
243 template<
typename SET_TYPE>
244 double time_set_insert(
int len)
248 SET_TYPE* set_objs =
new SET_TYPE[len];
254 int inner_2 = inner/2;
256 for(
int n=0; n<len; ++n) {
258 SET_TYPE& set_ref = set_objs[n];
260 for(
int i=0; i<outer; ++i) {
261 int col_i = col_n+i*outer;
263 for(
int j=0; j<inner_2; ++j) {
264 set_ref.insert(col_i+j);
265 set_ref.insert(col_i+j+inner_2);
273 return(elapsed_time);
276 template<
typename SET_TYPE>
277 double time_set_insert2(
int len)
281 SET_TYPE* set_objs =
new SET_TYPE[len];
288 for(
int n=0; n<len; ++n) {
290 SET_TYPE& set_ref = set_objs[n];
292 for(
int i=0; i<outer; ++i) {
293 int col_i = col_n+i*outer;
295 for(
int j=0; j<inner/2; ++j) {
296 set_ref.insert2(col_i+j);
297 set_ref.insert2(col_i+j+inner/2);
305 return(elapsed_time);
308 template<
typename SET_TYPE>
309 double benchmark_set()
314 double time_taken = time_set_insert<SET_TYPE>(len);
315 while(time_taken < 1.0) {
317 time_taken = time_set_insert<SET_TYPE>(len);
323 while(time_taken<5.0) {
324 time_taken += time_set_insert<SET_TYPE>(len);
328 return((
double)(i*len)/time_taken);
331 template<
typename SET_TYPE>
332 double benchmark_set2()
337 double time_taken = time_set_insert2<SET_TYPE>(len);
338 while(time_taken < 1.0) {
340 time_taken = time_set_insert2<SET_TYPE>(len);
346 while(time_taken<5.0) {
347 time_taken += time_set_insert2<SET_TYPE>(len);
351 return((
double)(i*len)/time_taken);
355 int test_benchmarks::test2()
360 FEI_COUT <<
"Following group of benchmarks inserts integers into sorted lists"
361 <<
" (actually"<<FEI_ENDL
362 <<
"sets), which is a sub-task of the ragged-table benchmarks..."<<FEI_ENDL
363 <<
"A higher number is better."<<FEI_ENDL<<FEI_ENDL;
365 print_benchmark_banner();
367 double value, goldvalue;
369 std::string testname;
372 value = benchmark_set<fei::ctg_set<int> >();
373 testname = add_macro_values(
"fei::ctg_set");
377 passfail = fei_test_utils::check_test_result(value, goldvalue, 10);
378 if (passfail !=
"passed") returnValue = -1;
385 print_benchmark_line(
"fei::ctg_set::insert", value, goldvalue, passfail.c_str());
388 #ifndef FEI_NO_STL_SET
390 value = benchmark_set<std::set<int> >();
393 print_benchmark_line(
"std::set::insert", value, goldvalue, passfail.c_str());
399 value = benchmark_set<FEI_HASH_SET<int> >();
402 print_benchmark_line(
"hash_set::insert", value, goldvalue, passfail.c_str());
405 FEI_COUT << FEI_ENDL;
406 FEI_COUT <<
"More list/set insertions..." << FEI_ENDL << FEI_ENDL;
408 print_benchmark_banner();
411 value = benchmark_set2<fei::ctg_set<int> >();
412 testname = add_macro_values(
"fei::ctg_set2");
416 passfail = fei_test_utils::check_test_result(value, goldvalue, 10);
417 if (passfail !=
"passed") returnValue = -1;
424 print_benchmark_line(
"fei::ctg_set::insert2", value, goldvalue, passfail.c_str());
426 FEI_COUT << FEI_ENDL;
427 if (returnValue != 0) {
428 FEI_COUT <<
"at least 1 benchmark failed."<< FEI_ENDL << FEI_ENDL;
434 int test_benchmarks::test3()
439 std::vector<int> stdvector(len);
441 std::vector<int> stdv_dest;
443 int* stdvptr = &(stdvector[0]);
445 for(
int i=0; i<len; ++i) {
449 FEI_COUT << FEI_ENDL <<
"time to perform " << n
450 <<
" binary-searches and inserts on an std::vector" << FEI_ENDL
451 <<
" of length " << len <<
": " << FEI_ENDL;
455 stdvector.reserve(n*2);
457 std::vector<int>::iterator
459 v_beg = stdvector.begin(),
460 v_end = stdvector.end();
462 for(
int k=0; k<n; ++k) {
463 v_iter = std::lower_bound(v_beg, v_end, k*2);
464 stdvector.insert(v_iter, k*2-1);
465 v_beg = stdvector.begin();
466 v_end = stdvector.end();
471 FEI_COUT << elapsed_time << FEI_ENDL;
476 int test_benchmarks::test4()
481 int test_benchmarks::test5()
486 int test_benchmarks::test6()
491 int test_benchmarks::test7()
496 int test_benchmarks::test8()
const std::string passfail(const bool result)
double get_file_benchmark(const char *filename, const char *testname)
void addIndices(int row, int numIndices, const int *indices)