23 using Teuchos::Ordinal;
26 double relCpuSpeed = 1e-2;
27 int maxArraySize = 10000;
28 double maxArrayBracketRatio =100.0;
29 double maxArrayIterRatio = 200.0;
30 double maxArrayRCPSelfIterRatio =200.0;
32 const int minArraySize = 100;
33 const int maxLoopIters = 1000;
34 const int intPrec = 8;
35 const int dblPrec = 6;
42 "rel-cpu-speed", &relCpuSpeed,
43 "The relative speed of the CPU (higher means the machine runs faster)"
46 "max-array-size", &maxArraySize,
47 "The maximum size of the arrays created"
50 "max-array-bracket-ratio", &maxArrayBracketRatio,
51 "The max allowed CPU timing ratio of the Array[RCP,View] braket operator relative"
52 " to the std::vector braket operator."
55 "max-array-iter-ratio", &maxArrayIterRatio,
56 "The max allowed CPU timing ratio of the Array[RCP,View] iterators relative"
57 " to using raw pointers as iterators."
60 "max-arrayrcp-self-iter-ratio", &maxArrayRCPSelfIterRatio,
61 "The max allowed CPU timing ratio of the ArrayrCP as a self iterator relative"
62 " to raw pointer arithmetic."
72 const double relTestCost = 1e-4;
74 const double numInnerLoops = relCpuSpeed / relTestCost;
77 <<
"Measuring the overhead of the Array braket operator relative to raw pointers.\n"
79 <<
"Number of loops = relCpuSpeed/relTestCost = "
80 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
83 TabularOutputter outputter(out);
84 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
85 outputter.setFieldTypePrecision(TO::INT, intPrec);
87 outputter.pushFieldSpec(
"array dim", TO::INT);
88 outputter.pushFieldSpec(
"num loops", TO::INT);
89 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
90 outputter.pushFieldSpec(
"vector", TO::DOUBLE);
91 outputter.pushFieldSpec(
"Array", TO::DOUBLE);
92 outputter.pushFieldSpec(
"vector/raw", TO::DOUBLE);
93 outputter.pushFieldSpec(
"Array/raw", TO::DOUBLE);
95 outputter.outputHeader();
98 double finalArrayBraketRatio = 100000.0;
100 Ordinal arraySize = minArraySize;
101 for (
int test_case_k = 0;
102 test_case_k < maxLoopIters && arraySize <= maxArraySize;
108 outputter.outputField(arraySize);
111 const int numActualLoops =
114 (numInnerLoops / arraySize)
115 * std::log(static_cast<double>(arraySize+1))
119 outputter.outputField(numActualLoops);
121 std::vector<double> vec(arraySize);
125 double *p_raw = &vec[0];
128 for (Ordinal i=0; i < arraySize; ++i)
137 for (Ordinal i=0; i < arraySize; ++i)
147 for (Ordinal i=0; i < arraySize; ++i)
154 const double vectorRatio = vectorTime / rawPtrTime;
155 outputter.outputField(vectorRatio);
158 const double arrayRatio = arrayTime / rawPtrTime;
159 outputter.outputField(arrayRatio);
164 finalArrayBraketRatio =
TEUCHOS_MIN(arrayRatio, finalArrayBraketRatio);
169 TEST_COMPARE( finalArrayBraketRatio, <=, maxArrayBracketRatio );
180 const double relTestCost = 1e-4;
182 const double numInnerLoops = relCpuSpeed / relTestCost;
185 <<
"Measuring the overhead of the ArrayView braket operator relative to raw pointers.\n"
187 <<
"Number of loops = relCpuSpeed/relTestCost = "
188 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
191 TabularOutputter outputter(out);
192 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
193 outputter.setFieldTypePrecision(TO::INT, intPrec);
195 outputter.pushFieldSpec(
"array dim", TO::INT);
196 outputter.pushFieldSpec(
"num loops", TO::INT);
197 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
198 outputter.pushFieldSpec(
"ArrayView", TO::DOUBLE);
199 outputter.pushFieldSpec(
"ArrayView/raw", TO::DOUBLE);
201 outputter.outputHeader();
204 double finalArrayViewBraketRatio = 100000.0;
206 Ordinal arraySize = minArraySize;
207 for (
int test_case_k = 0;
208 test_case_k < maxLoopIters && arraySize <= maxArraySize;
214 outputter.outputField(arraySize);
217 const int numActualLoops =
220 (numInnerLoops / arraySize)
221 * std::log(static_cast<double>(arraySize+1))
225 outputter.outputField(numActualLoops);
227 std::vector<double> vec(arraySize);
230 double *p_raw = &vec[0];
233 for (Ordinal i=0; i < arraySize; ++i)
243 for (Ordinal i=0; i < arraySize; ++i)
249 const double arrayviewRatio = arrayviewTime / rawPtrTime;
250 outputter.outputField(arrayviewRatio);
255 finalArrayViewBraketRatio =
TEUCHOS_MIN(arrayviewRatio, finalArrayViewBraketRatio);
260 TEST_COMPARE( finalArrayViewBraketRatio, <=, maxArrayBracketRatio );
271 const double relTestCost = 1e-4;
273 const double numInnerLoops = relCpuSpeed / relTestCost;
276 <<
"Measuring the overhead of the ArrayRCP braket operator relative to raw pointers.\n"
278 <<
"Number of loops = relCpuSpeed/relTestCost = "
279 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
282 TabularOutputter outputter(out);
283 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
284 outputter.setFieldTypePrecision(TO::INT, intPrec);
286 outputter.pushFieldSpec(
"array dim", TO::INT);
287 outputter.pushFieldSpec(
"num loops", TO::INT);
288 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
289 outputter.pushFieldSpec(
"ArrayRCP", TO::DOUBLE);
290 outputter.pushFieldSpec(
"ArrayRCP/raw", TO::DOUBLE);
292 outputter.outputHeader();
295 double finalArrayRCPBraketRatio = 100000.0;
297 Ordinal arraySize = minArraySize;
298 for (
int test_case_k = 0;
299 test_case_k < maxLoopIters && arraySize <= maxArraySize;
305 outputter.outputField(arraySize);
308 const int numActualLoops =
311 (numInnerLoops / arraySize)
312 * std::log(static_cast<double>(arraySize+1))
316 outputter.outputField(numActualLoops);
318 std::vector<double> vec(arraySize);
321 double *p_raw = &vec[0];
324 for (Ordinal i=0; i < arraySize; ++i)
333 for (Ordinal i=0; i < arraySize; ++i)
339 const double arrayrcpRatio = arrayrcpTime / rawPtrTime;
340 outputter.outputField(arrayrcpRatio);
345 finalArrayRCPBraketRatio =
TEUCHOS_MIN(arrayrcpRatio, finalArrayRCPBraketRatio);
350 TEST_COMPARE( finalArrayRCPBraketRatio, <=, maxArrayBracketRatio );
361 const double relTestCost = 1e-4;
363 const double numInnerLoops = relCpuSpeed / relTestCost;
366 <<
"Measuring the overhead of the Array iterators relative to raw pointers.\n"
368 <<
"Number of loops = relCpuSpeed/relTestCost = "
369 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
372 TabularOutputter outputter(out);
373 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
374 outputter.setFieldTypePrecision(TO::INT, intPrec);
376 outputter.pushFieldSpec(
"array dim", TO::INT);
377 outputter.pushFieldSpec(
"num loops", TO::INT);
378 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
379 outputter.pushFieldSpec(
"vector", TO::DOUBLE);
380 outputter.pushFieldSpec(
"Array", TO::DOUBLE);
381 outputter.pushFieldSpec(
"vector/raw", TO::DOUBLE);
382 outputter.pushFieldSpec(
"Array/raw", TO::DOUBLE);
384 outputter.outputHeader();
387 double finalArrayIterRatio = 100000.0;
389 Ordinal arraySize = minArraySize;
390 for (
int test_case_k = 0;
391 test_case_k < maxLoopIters && arraySize <= maxArraySize;
397 outputter.outputField(arraySize);
400 const int numActualLoops =
403 (numInnerLoops / arraySize)
404 * std::log(static_cast<double>(arraySize+1))
408 outputter.outputField(numActualLoops);
410 std::vector<double> vec(arraySize);
416 *p_raw_itr = &vec[0],
417 *p_raw_end = &vec[0] + arraySize;
418 for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
426 std::vector<double>::iterator
427 vec_itr = vec.begin(),
429 for ( ; vec_itr < vec_end; ++vec_itr)
441 for ( ; a_itr < a_end; ++a_itr)
447 const double vectorRatio = vectorTime / rawPtrTime;
448 outputter.outputField(vectorRatio);
451 const double arrayRatio = arrayTime / rawPtrTime;
452 outputter.outputField(arrayRatio);
457 finalArrayIterRatio =
TEUCHOS_MIN(arrayRatio, finalArrayIterRatio);
462 TEST_COMPARE( finalArrayIterRatio, <=, maxArrayIterRatio );
473 const double relTestCost = 1e-4;
475 const double numInnerLoops = relCpuSpeed / relTestCost;
478 <<
"Measuring the overhead of the ArrayView iterators relative to raw pointers.\n"
480 <<
"Number of loops = relCpuSpeed/relTestCost = "
481 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
484 TabularOutputter outputter(out);
485 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
486 outputter.setFieldTypePrecision(TO::INT, intPrec);
488 outputter.pushFieldSpec(
"array dim", TO::INT);
489 outputter.pushFieldSpec(
"num loops", TO::INT);
490 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
491 outputter.pushFieldSpec(
"ArrayView", TO::DOUBLE);
492 outputter.pushFieldSpec(
"ArrayView/raw", TO::DOUBLE);
494 outputter.outputHeader();
497 double finalArrayViewIterRatio = 100000.0;
499 Ordinal arraySize = minArraySize;
500 for (
int test_case_k = 0;
501 test_case_k < maxLoopIters && arraySize <= maxArraySize;
507 outputter.outputField(arraySize);
510 const int numActualLoops =
513 (numInnerLoops / arraySize)
514 * std::log(static_cast<double>(arraySize+1))
518 outputter.outputField(numActualLoops);
520 std::vector<double> vec(arraySize);
526 *p_raw_itr = &vec[0],
527 *p_raw_end = &vec[0] + arraySize;
528 for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
541 for ( ; av_itr < av_end ; ++av_itr)
547 const double arrayviewRatio = arrayviewTime / rawPtrTime;
548 outputter.outputField(arrayviewRatio);
553 finalArrayViewIterRatio =
TEUCHOS_MIN(arrayviewRatio, finalArrayViewIterRatio);
558 TEST_COMPARE( finalArrayViewIterRatio, <=, maxArrayIterRatio );
569 const double relTestCost = 1e-4;
571 const double numInnerLoops = relCpuSpeed / relTestCost;
574 <<
"Measuring the overhead of the ArrayRCP iterators relative to raw pointers.\n"
576 <<
"Number of loops = relCpuSpeed/relTestCost = "
577 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
580 TabularOutputter outputter(out);
581 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
582 outputter.setFieldTypePrecision(TO::INT, intPrec);
584 outputter.pushFieldSpec(
"array dim", TO::INT);
585 outputter.pushFieldSpec(
"num loops", TO::INT);
586 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
587 outputter.pushFieldSpec(
"ArrayRCP", TO::DOUBLE);
588 outputter.pushFieldSpec(
"ArrayRCP/raw", TO::DOUBLE);
590 outputter.outputHeader();
593 double finalArrayRCPIterRatio = 100000.0;
595 Ordinal arraySize = minArraySize;
596 for (
int test_case_k = 0;
597 test_case_k < maxLoopIters && arraySize <= maxArraySize;
603 outputter.outputField(arraySize);
606 const int numActualLoops =
609 (numInnerLoops / arraySize)
610 * std::log(static_cast<double>(arraySize+1))
614 outputter.outputField(numActualLoops);
616 std::vector<double> vec(arraySize);
622 *p_raw_itr = &vec[0],
623 *p_raw_end = &vec[0] + arraySize;
624 for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
636 for ( ; ap_itr < ap_end; ++ap_itr)
642 const double arrayviewRatio = arrayviewTime / rawPtrTime;
643 outputter.outputField(arrayviewRatio);
648 finalArrayRCPIterRatio =
TEUCHOS_MIN(arrayviewRatio, finalArrayRCPIterRatio);
653 TEST_COMPARE( finalArrayRCPIterRatio, <=, maxArrayIterRatio );
664 const double relTestCost = 1e-4;
666 const double numInnerLoops = relCpuSpeed / relTestCost;
669 <<
"Measuring the overhead of the ArrayRCP as a self iterataor relative to raw pointers.\n"
671 <<
"Number of loops = relCpuSpeed/relTestCost = "
672 << relCpuSpeed <<
"/" << relTestCost <<
" = " << numInnerLoops <<
"\n"
675 TabularOutputter outputter(out);
676 outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
677 outputter.setFieldTypePrecision(TO::INT, intPrec);
679 outputter.pushFieldSpec(
"array dim", TO::INT);
680 outputter.pushFieldSpec(
"num loops", TO::INT);
681 outputter.pushFieldSpec(
"raw ptr", TO::DOUBLE);
682 outputter.pushFieldSpec(
"ArrayRCP", TO::DOUBLE);
683 outputter.pushFieldSpec(
"ArrayRCP/raw", TO::DOUBLE);
685 outputter.outputHeader();
688 double finalArrayRCPIterRatio = 100000.0;
690 Ordinal arraySize = minArraySize;
691 for (
int test_case_k = 0;
692 test_case_k < maxLoopIters && arraySize <= maxArraySize;
698 outputter.outputField(arraySize);
701 const int numActualLoops =
704 (numInnerLoops / arraySize)
705 * std::log(static_cast<double>(arraySize+1))
709 outputter.outputField(numActualLoops);
711 std::vector<double> vec(arraySize);
717 *p_raw_itr = &vec[0],
718 *p_raw_end = &vec[0] + arraySize;
719 for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
730 ap_end = ap + arraySize;
731 for ( ; ap_itr < ap_end; ++ap_itr)
737 const double arrayviewRatio = arrayviewTime / rawPtrTime;
738 outputter.outputField(arrayviewRatio);
743 finalArrayRCPIterRatio =
TEUCHOS_MIN(arrayviewRatio, finalArrayRCPIterRatio);
748 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.