57 using Teuchos::Ordinal;
60 double relCpuSpeed = 1e-2;
61 int maxArraySize = 10000;
62 double maxArrayBracketRatio =100.0;
63 double maxArrayIterRatio = 100.0;
64 double maxArrayRCPSelfIterRatio =200.0;
66 const int minArraySize = 100;
67 const int maxLoopIters = 1000;
68 const int intPrec = 8;
69 const int dblPrec = 6;
76 "rel-cpu-speed", &relCpuSpeed,
77 "The relative speed of the CPU (higher means the machine runs faster)"
80 "max-array-size", &maxArraySize,
81 "The maximum size of the arrays created"
84 "max-array-bracket-ratio", &maxArrayBracketRatio,
85 "The max allowed CPU timing ratio of the Array[RCP,View] braket operator relative"
86 " to the std::vector braket operator."
89 "max-array-iter-ratio", &maxArrayIterRatio,
90 "The max allowed CPU timing ratio of the Array[RCP,View] iterators relative"
91 " to using raw pointers as iterators."
94 "max-arrayrcp-self-iter-ratio", &maxArrayRCPSelfIterRatio,
95 "The max allowed CPU timing ratio of the ArrayrCP as a self iterator relative"
96 " to raw pointer arithmetic."
106 const double relTestCost = 1e-4;
108 const double numInnerLoops = relCpuSpeed / relTestCost;
111 <<
"Measuring the overhead of the Array braket operator relative to raw pointers.\n"
113 <<
"Number of loops = relCpuSpeed/relTestCost = "
114 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
117 TabularOutputter outputter(out);
118 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
119 outputter.setFieldTypePrecision(TO::INT, intPrec);
121 outputter.pushFieldSpec(
"array dim", TO::INT);
122 outputter.pushFieldSpec(
"num loops", TO::INT);
123 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
124 outputter.pushFieldSpec(
"vector", TO::DOUBLE);
125 outputter.pushFieldSpec(
"Array", TO::DOUBLE);
126 outputter.pushFieldSpec(
"vector/raw", TO::DOUBLE);
127 outputter.pushFieldSpec(
"Array/raw", TO::DOUBLE);
129 outputter.outputHeader();
132 double finalArrayBraketRatio = 100000.0;
134 Ordinal arraySize = minArraySize;
135 for (
int test_case_k = 0;
136 test_case_k < maxLoopIters && arraySize <= maxArraySize;
142 outputter.outputField(arraySize);
145 const int numActualLoops =
148 (numInnerLoops / arraySize)
149 * std::log(static_cast<double>(arraySize+1))
153 outputter.outputField(numActualLoops);
155 std::vector<double> vec(arraySize);
159 double *p_raw = &vec[0];
162 for (Ordinal i=0; i < arraySize; ++i)
171 for (Ordinal i=0; i < arraySize; ++i)
181 for (Ordinal i=0; i < arraySize; ++i)
188 const double vectorRatio = vectorTime / rawPtrTime;
189 outputter.outputField(vectorRatio);
192 const double arrayRatio = arrayTime / rawPtrTime;
193 outputter.outputField(arrayRatio);
198 finalArrayBraketRatio =
TEUCHOS_MIN(arrayRatio, finalArrayBraketRatio);
203 TEST_COMPARE( finalArrayBraketRatio, <=, maxArrayBracketRatio );
214 const double relTestCost = 1e-4;
216 const double numInnerLoops = relCpuSpeed / relTestCost;
219 <<
"Measuring the overhead of the ArrayView braket operator relative to raw pointers.\n"
221 <<
"Number of loops = relCpuSpeed/relTestCost = "
222 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
225 TabularOutputter outputter(out);
226 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
227 outputter.setFieldTypePrecision(TO::INT, intPrec);
229 outputter.pushFieldSpec(
"array dim", TO::INT);
230 outputter.pushFieldSpec(
"num loops", TO::INT);
231 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
232 outputter.pushFieldSpec(
"ArrayView", TO::DOUBLE);
233 outputter.pushFieldSpec(
"ArrayView/raw", TO::DOUBLE);
235 outputter.outputHeader();
238 double finalArrayViewBraketRatio = 100000.0;
240 Ordinal arraySize = minArraySize;
241 for (
int test_case_k = 0;
242 test_case_k < maxLoopIters && arraySize <= maxArraySize;
248 outputter.outputField(arraySize);
251 const int numActualLoops =
254 (numInnerLoops / arraySize)
255 * std::log(static_cast<double>(arraySize+1))
259 outputter.outputField(numActualLoops);
261 std::vector<double> vec(arraySize);
264 double *p_raw = &vec[0];
267 for (Ordinal i=0; i < arraySize; ++i)
277 for (Ordinal i=0; i < arraySize; ++i)
283 const double arrayviewRatio = arrayviewTime / rawPtrTime;
284 outputter.outputField(arrayviewRatio);
289 finalArrayViewBraketRatio =
TEUCHOS_MIN(arrayviewRatio, finalArrayViewBraketRatio);
294 TEST_COMPARE( finalArrayViewBraketRatio, <=, maxArrayBracketRatio );
305 const double relTestCost = 1e-4;
307 const double numInnerLoops = relCpuSpeed / relTestCost;
310 <<
"Measuring the overhead of the ArrayRCP braket operator relative to raw pointers.\n"
312 <<
"Number of loops = relCpuSpeed/relTestCost = "
313 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
316 TabularOutputter outputter(out);
317 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
318 outputter.setFieldTypePrecision(TO::INT, intPrec);
320 outputter.pushFieldSpec(
"array dim", TO::INT);
321 outputter.pushFieldSpec(
"num loops", TO::INT);
322 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
323 outputter.pushFieldSpec(
"ArrayRCP", TO::DOUBLE);
324 outputter.pushFieldSpec(
"ArrayRCP/raw", TO::DOUBLE);
326 outputter.outputHeader();
329 double finalArrayRCPBraketRatio = 100000.0;
331 Ordinal arraySize = minArraySize;
332 for (
int test_case_k = 0;
333 test_case_k < maxLoopIters && arraySize <= maxArraySize;
339 outputter.outputField(arraySize);
342 const int numActualLoops =
345 (numInnerLoops / arraySize)
346 * std::log(static_cast<double>(arraySize+1))
350 outputter.outputField(numActualLoops);
352 std::vector<double> vec(arraySize);
355 double *p_raw = &vec[0];
358 for (Ordinal i=0; i < arraySize; ++i)
367 for (Ordinal i=0; i < arraySize; ++i)
373 const double arrayrcpRatio = arrayrcpTime / rawPtrTime;
374 outputter.outputField(arrayrcpRatio);
379 finalArrayRCPBraketRatio =
TEUCHOS_MIN(arrayrcpRatio, finalArrayRCPBraketRatio);
384 TEST_COMPARE( finalArrayRCPBraketRatio, <=, maxArrayBracketRatio );
395 const double relTestCost = 1e-4;
397 const double numInnerLoops = relCpuSpeed / relTestCost;
400 <<
"Measuring the overhead of the Array iterators relative to raw pointers.\n"
402 <<
"Number of loops = relCpuSpeed/relTestCost = "
403 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
406 TabularOutputter outputter(out);
407 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
408 outputter.setFieldTypePrecision(TO::INT, intPrec);
410 outputter.pushFieldSpec(
"array dim", TO::INT);
411 outputter.pushFieldSpec(
"num loops", TO::INT);
412 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
413 outputter.pushFieldSpec(
"vector", TO::DOUBLE);
414 outputter.pushFieldSpec(
"Array", TO::DOUBLE);
415 outputter.pushFieldSpec(
"vector/raw", TO::DOUBLE);
416 outputter.pushFieldSpec(
"Array/raw", TO::DOUBLE);
418 outputter.outputHeader();
421 double finalArrayIterRatio = 100000.0;
423 Ordinal arraySize = minArraySize;
424 for (
int test_case_k = 0;
425 test_case_k < maxLoopIters && arraySize <= maxArraySize;
431 outputter.outputField(arraySize);
434 const int numActualLoops =
437 (numInnerLoops / arraySize)
438 * std::log(static_cast<double>(arraySize+1))
442 outputter.outputField(numActualLoops);
444 std::vector<double> vec(arraySize);
450 *p_raw_itr = &vec[0],
451 *p_raw_end = &vec[0] + arraySize;
452 for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
460 std::vector<double>::iterator
461 vec_itr = vec.begin(),
463 for ( ; vec_itr < vec_end; ++vec_itr)
475 for ( ; a_itr < a_end; ++a_itr)
481 const double vectorRatio = vectorTime / rawPtrTime;
482 outputter.outputField(vectorRatio);
485 const double arrayRatio = arrayTime / rawPtrTime;
486 outputter.outputField(arrayRatio);
491 finalArrayIterRatio =
TEUCHOS_MIN(arrayRatio, finalArrayIterRatio);
496 TEST_COMPARE( finalArrayIterRatio, <=, maxArrayIterRatio );
507 const double relTestCost = 1e-4;
509 const double numInnerLoops = relCpuSpeed / relTestCost;
512 <<
"Measuring the overhead of the ArrayView iterators relative to raw pointers.\n"
514 <<
"Number of loops = relCpuSpeed/relTestCost = "
515 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
518 TabularOutputter outputter(out);
519 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
520 outputter.setFieldTypePrecision(TO::INT, intPrec);
522 outputter.pushFieldSpec(
"array dim", TO::INT);
523 outputter.pushFieldSpec(
"num loops", TO::INT);
524 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
525 outputter.pushFieldSpec(
"ArrayView", TO::DOUBLE);
526 outputter.pushFieldSpec(
"ArrayView/raw", TO::DOUBLE);
528 outputter.outputHeader();
531 double finalArrayViewIterRatio = 100000.0;
533 Ordinal arraySize = minArraySize;
534 for (
int test_case_k = 0;
535 test_case_k < maxLoopIters && arraySize <= maxArraySize;
541 outputter.outputField(arraySize);
544 const int numActualLoops =
547 (numInnerLoops / arraySize)
548 * std::log(static_cast<double>(arraySize+1))
552 outputter.outputField(numActualLoops);
554 std::vector<double> vec(arraySize);
560 *p_raw_itr = &vec[0],
561 *p_raw_end = &vec[0] + arraySize;
562 for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
575 for ( ; av_itr < av_end ; ++av_itr)
581 const double arrayviewRatio = arrayviewTime / rawPtrTime;
582 outputter.outputField(arrayviewRatio);
587 finalArrayViewIterRatio =
TEUCHOS_MIN(arrayviewRatio, finalArrayViewIterRatio);
592 TEST_COMPARE( finalArrayViewIterRatio, <=, maxArrayIterRatio );
603 const double relTestCost = 1e-4;
605 const double numInnerLoops = relCpuSpeed / relTestCost;
608 <<
"Measuring the overhead of the ArrayRCP iterators relative to raw pointers.\n"
610 <<
"Number of loops = relCpuSpeed/relTestCost = "
611 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
614 TabularOutputter outputter(out);
615 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
616 outputter.setFieldTypePrecision(TO::INT, intPrec);
618 outputter.pushFieldSpec(
"array dim", TO::INT);
619 outputter.pushFieldSpec(
"num loops", TO::INT);
620 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
621 outputter.pushFieldSpec(
"ArrayRCP", TO::DOUBLE);
622 outputter.pushFieldSpec(
"ArrayRCP/raw", TO::DOUBLE);
624 outputter.outputHeader();
627 double finalArrayRCPIterRatio = 100000.0;
629 Ordinal arraySize = minArraySize;
630 for (
int test_case_k = 0;
631 test_case_k < maxLoopIters && arraySize <= maxArraySize;
637 outputter.outputField(arraySize);
640 const int numActualLoops =
643 (numInnerLoops / arraySize)
644 * std::log(static_cast<double>(arraySize+1))
648 outputter.outputField(numActualLoops);
650 std::vector<double> vec(arraySize);
656 *p_raw_itr = &vec[0],
657 *p_raw_end = &vec[0] + arraySize;
658 for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
670 for ( ; ap_itr < ap_end; ++ap_itr)
676 const double arrayviewRatio = arrayviewTime / rawPtrTime;
677 outputter.outputField(arrayviewRatio);
682 finalArrayRCPIterRatio =
TEUCHOS_MIN(arrayviewRatio, finalArrayRCPIterRatio);
687 TEST_COMPARE( finalArrayRCPIterRatio, <=, maxArrayIterRatio );
698 const double relTestCost = 1e-4;
700 const double numInnerLoops = relCpuSpeed / relTestCost;
703 <<
"Measuring the overhead of the ArrayRCP as a self iterataor relative to raw pointers.\n"
705 <<
"Number of loops = relCpuSpeed/relTestCost = "
706 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
709 TabularOutputter outputter(out);
710 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
711 outputter.setFieldTypePrecision(TO::INT, intPrec);
713 outputter.pushFieldSpec(
"array dim", TO::INT);
714 outputter.pushFieldSpec(
"num loops", TO::INT);
715 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
716 outputter.pushFieldSpec(
"ArrayRCP", TO::DOUBLE);
717 outputter.pushFieldSpec(
"ArrayRCP/raw", TO::DOUBLE);
719 outputter.outputHeader();
722 double finalArrayRCPIterRatio = 100000.0;
724 Ordinal arraySize = minArraySize;
725 for (
int test_case_k = 0;
726 test_case_k < maxLoopIters && arraySize <= maxArraySize;
732 outputter.outputField(arraySize);
735 const int numActualLoops =
738 (numInnerLoops / arraySize)
739 * std::log(static_cast<double>(arraySize+1))
743 outputter.outputField(numActualLoops);
745 std::vector<double> vec(arraySize);
751 *p_raw_itr = &vec[0],
752 *p_raw_end = &vec[0] + arraySize;
753 for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
764 ap_end = ap + arraySize;
765 for ( ; ap_itr < ap_end; ++ap_itr)
771 const double arrayviewRatio = arrayviewTime / rawPtrTime;
772 outputter.outputField(arrayviewRatio);
777 finalArrayRCPIterRatio =
TEUCHOS_MIN(arrayviewRatio, finalArrayRCPIterRatio);
782 TEST_COMPARE( finalArrayRCPIterRatio, <=, maxArrayRCPSelfIterRatio );
pointer iterator
Type of a nonconst iterator.
iterator begin() const
Return an iterator to beginning of the array of data.
static CommandLineProcessor & getCLP()
Return the CLP to add options to.
#define TEST_COMPARE(v1, comp, v2)
Assert that v1 comp v2 (where comp = '==', '>=", "!=", etc).
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Utility class that makes it easy to create formatted tables of output.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
#define TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(OUTPUTTER, NUMLOOPS, NUMINNERLOOPS)
Start a timer block using a TabularOutputter object .
#define TEUCHOS_END_PERF_OUTPUT_TIMER(OUTPUTTER, VARNAME)
End a timer block, output the time field to a TabularOutputter object, and set a variable with the ti...
#define TEUCHOS_MAX(x, y)
Templated array class derived from the STL std::vector.
iterator end() const
Return an iterator to past the end of the array of data.
Smart reference counting pointer class for automatic garbage collection.
T * iterator
Nonconstant iterator type used if bounds checking is disabled.
iterator end() const
Return an iterator to past the end of the array of data.
std::vector< T >::iterator iterator
The type of a forward iterator.
#define TEUCHOS_MIN(x, y)
Class that helps parse command line input arguments from (argc,argv[]) and set options.
iterator begin() const
Return an iterator to beginning of the array of data.
Reference-counted smart pointer for managing arrays.