Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Array_Performance_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
12 
13 #include "Teuchos_Array.hpp"
14 
15 
16 namespace {
17 
18 
19 using Teuchos::null;
20 using Teuchos::RCP;
21 using Teuchos::rcp;
23 using Teuchos::Ordinal;
24 
25 
26 double relCpuSpeed = 1e-2;
27 int maxArraySize = 10000;
28 double maxArrayBracketRatio =100.0;
29 double maxArrayIterRatio = 200.0;
30 double maxArrayRCPSelfIterRatio =200.0;
31 
32 const int minArraySize = 100;
33 const int maxLoopIters = 1000;
34 const int intPrec = 8;
35 const int dblPrec = 6;
36 
38 {
41  clp.setOption(
42  "rel-cpu-speed", &relCpuSpeed,
43  "The relative speed of the CPU (higher means the machine runs faster)"
44  );
45  clp.setOption(
46  "max-array-size", &maxArraySize,
47  "The maximum size of the arrays created"
48  );
49  clp.setOption(
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."
53  );
54  clp.setOption(
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."
58  );
59  clp.setOption(
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."
63  );
64 }
65 
66 
67 TEUCHOS_UNIT_TEST( Array, braketOperatorOverhead )
68 {
69 
70  typedef Teuchos::TabularOutputter TO;
71 
72  const double relTestCost = 1e-4;
73 
74  const double numInnerLoops = relCpuSpeed / relTestCost;
75 
76  out << "\n"
77  << "Measuring the overhead of the Array braket operator relative to raw pointers.\n"
78  << "\n"
79  << "Number of loops = relCpuSpeed/relTestCost = "
80  << relCpuSpeed << "/" << relTestCost << " = " << numInnerLoops << "\n"
81  << "\n";
82 
83  TabularOutputter outputter(out);
84  outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
85  outputter.setFieldTypePrecision(TO::INT, intPrec);
86 
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);
94 
95  outputter.outputHeader();
96 
97  // Start out really big to make sure it fails if not set correctly!
98  double finalArrayBraketRatio = 100000.0;
99 
100  Ordinal arraySize = minArraySize;
101  for (int test_case_k = 0;
102  test_case_k < maxLoopIters && arraySize <= maxArraySize;
103  ++test_case_k
104  )
105  {
106 
107  // array dim
108  outputter.outputField(arraySize);
109 
110  // num loops
111  const int numActualLoops =
112  TEUCHOS_MAX(
113  static_cast<int>(
114  (numInnerLoops / arraySize)
115  * std::log(static_cast<double>(arraySize+1))
116  ),
117  1
118  );
119  outputter.outputField(numActualLoops);
120 
121  std::vector<double> vec(arraySize);
122 
123  // raw ptr
124  {
125  double *p_raw = &vec[0];
126  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
127  {
128  for (Ordinal i=0; i < arraySize; ++i)
129  p_raw[i] = 0.0;
130  }
131  }
132  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
133 
134  // vector
135  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
136  {
137  for (Ordinal i=0; i < arraySize; ++i)
138  vec[i] = 0.0;
139  }
140  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, vectorTime);
141 
142  // Array
143  {
144  Teuchos::Array<double> a(arraySize);
145  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
146  {
147  for (Ordinal i=0; i < arraySize; ++i)
148  a[i] = 0.0;
149  }
150  }
151  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, arrayTime);
152 
153  // vector/raw
154  const double vectorRatio = vectorTime / rawPtrTime;
155  outputter.outputField(vectorRatio);
156 
157  // Array/raw
158  const double arrayRatio = arrayTime / rawPtrTime;
159  outputter.outputField(arrayRatio);
160 
161  outputter.nextRow();
162 
163  arraySize *= 4;
164  finalArrayBraketRatio = TEUCHOS_MIN(arrayRatio, finalArrayBraketRatio);
165 
166  }
167 
168  out << "\n";
169  TEST_COMPARE( finalArrayBraketRatio, <=, maxArrayBracketRatio );
170  out << "\n";
171 
172 }
173 
174 
175 TEUCHOS_UNIT_TEST( ArrayView, braketOperatorOverhead )
176 {
177 
178  typedef Teuchos::TabularOutputter TO;
179 
180  const double relTestCost = 1e-4;
181 
182  const double numInnerLoops = relCpuSpeed / relTestCost;
183 
184  out << "\n"
185  << "Measuring the overhead of the ArrayView braket operator relative to raw pointers.\n"
186  << "\n"
187  << "Number of loops = relCpuSpeed/relTestCost = "
188  << relCpuSpeed << "/" << relTestCost << " = " << numInnerLoops << "\n"
189  << "\n";
190 
191  TabularOutputter outputter(out);
192  outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
193  outputter.setFieldTypePrecision(TO::INT, intPrec);
194 
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);
200 
201  outputter.outputHeader();
202 
203  // Start out really big to make sure it fails if not set correctly!
204  double finalArrayViewBraketRatio = 100000.0;
205 
206  Ordinal arraySize = minArraySize;
207  for (int test_case_k = 0;
208  test_case_k < maxLoopIters && arraySize <= maxArraySize;
209  ++test_case_k
210  )
211  {
212 
213  // array dim
214  outputter.outputField(arraySize);
215 
216  // num loops
217  const int numActualLoops =
218  TEUCHOS_MAX(
219  static_cast<int>(
220  (numInnerLoops / arraySize)
221  * std::log(static_cast<double>(arraySize+1))
222  ),
223  1
224  );
225  outputter.outputField(numActualLoops);
226 
227  std::vector<double> vec(arraySize);
228 
229  // raw ptr
230  double *p_raw = &vec[0];
231  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
232  {
233  for (Ordinal i=0; i < arraySize; ++i)
234  p_raw[i] = 0.0;
235  }
236  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
237 
238  // ArrayView
239  Teuchos::Array<double> a(arraySize);
241  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
242  {
243  for (Ordinal i=0; i < arraySize; ++i)
244  av[i] = 0.0;
245  }
246  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, arrayviewTime);
247 
248  // Array/raw
249  const double arrayviewRatio = arrayviewTime / rawPtrTime;
250  outputter.outputField(arrayviewRatio);
251 
252  outputter.nextRow();
253 
254  arraySize *= 4;
255  finalArrayViewBraketRatio = TEUCHOS_MIN(arrayviewRatio, finalArrayViewBraketRatio);
256 
257  }
258 
259  out << "\n";
260  TEST_COMPARE( finalArrayViewBraketRatio, <=, maxArrayBracketRatio );
261  out << "\n";
262 
263 }
264 
265 
266 TEUCHOS_UNIT_TEST( ArrayRCP, braketOperatorOverhead )
267 {
268 
269  typedef Teuchos::TabularOutputter TO;
270 
271  const double relTestCost = 1e-4;
272 
273  const double numInnerLoops = relCpuSpeed / relTestCost;
274 
275  out << "\n"
276  << "Measuring the overhead of the ArrayRCP braket operator relative to raw pointers.\n"
277  << "\n"
278  << "Number of loops = relCpuSpeed/relTestCost = "
279  << relCpuSpeed << "/" << relTestCost << " = " << numInnerLoops << "\n"
280  << "\n";
281 
282  TabularOutputter outputter(out);
283  outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
284  outputter.setFieldTypePrecision(TO::INT, intPrec);
285 
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);
291 
292  outputter.outputHeader();
293 
294  // Start out really big to make sure it fails if not set correctly!
295  double finalArrayRCPBraketRatio = 100000.0;
296 
297  Ordinal arraySize = minArraySize;
298  for (int test_case_k = 0;
299  test_case_k < maxLoopIters && arraySize <= maxArraySize;
300  ++test_case_k
301  )
302  {
303 
304  // array dim
305  outputter.outputField(arraySize);
306 
307  // num loops
308  const int numActualLoops =
309  TEUCHOS_MAX(
310  static_cast<int>(
311  (numInnerLoops / arraySize)
312  * std::log(static_cast<double>(arraySize+1))
313  ),
314  1
315  );
316  outputter.outputField(numActualLoops);
317 
318  std::vector<double> vec(arraySize);
319 
320  // raw ptr
321  double *p_raw = &vec[0];
322  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
323  {
324  for (Ordinal i=0; i < arraySize; ++i)
325  p_raw[i] = 0.0;
326  }
327  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
328 
329  // ArrayRCP
330  Teuchos::ArrayRCP<double> arcp = Teuchos::arcp<double>(arraySize);
331  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
332  {
333  for (Ordinal i=0; i < arraySize; ++i)
334  arcp[i] = 0.0;
335  }
336  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, arrayrcpTime);
337 
338  // Array/raw
339  const double arrayrcpRatio = arrayrcpTime / rawPtrTime;
340  outputter.outputField(arrayrcpRatio);
341 
342  outputter.nextRow();
343 
344  arraySize *= 4;
345  finalArrayRCPBraketRatio = TEUCHOS_MIN(arrayrcpRatio, finalArrayRCPBraketRatio);
346 
347  }
348 
349  out << "\n";
350  TEST_COMPARE( finalArrayRCPBraketRatio, <=, maxArrayBracketRatio );
351  out << "\n";
352 
353 }
354 
355 
356 TEUCHOS_UNIT_TEST( Array, iteratorOverhead )
357 {
358 
359  typedef Teuchos::TabularOutputter TO;
360 
361  const double relTestCost = 1e-4;
362 
363  const double numInnerLoops = relCpuSpeed / relTestCost;
364 
365  out << "\n"
366  << "Measuring the overhead of the Array iterators relative to raw pointers.\n"
367  << "\n"
368  << "Number of loops = relCpuSpeed/relTestCost = "
369  << relCpuSpeed << "/" << relTestCost << " = " << numInnerLoops << "\n"
370  << "\n";
371 
372  TabularOutputter outputter(out);
373  outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
374  outputter.setFieldTypePrecision(TO::INT, intPrec);
375 
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);
383 
384  outputter.outputHeader();
385 
386  // Start out really big to make sure it fails if not set correctly!
387  double finalArrayIterRatio = 100000.0;
388 
389  Ordinal arraySize = minArraySize;
390  for (int test_case_k = 0;
391  test_case_k < maxLoopIters && arraySize <= maxArraySize;
392  ++test_case_k
393  )
394  {
395 
396  // array dim
397  outputter.outputField(arraySize);
398 
399  // num loops
400  const int numActualLoops =
401  TEUCHOS_MAX(
402  static_cast<int>(
403  (numInnerLoops / arraySize)
404  * std::log(static_cast<double>(arraySize+1))
405  ),
406  1
407  );
408  outputter.outputField(numActualLoops);
409 
410  std::vector<double> vec(arraySize);
411 
412  // raw ptr
413  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
414  {
415  double
416  *p_raw_itr = &vec[0],
417  *p_raw_end = &vec[0] + arraySize;
418  for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
419  *p_raw_itr = 0.0;
420  }
421  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
422 
423  // vector
424  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
425  {
426  std::vector<double>::iterator
427  vec_itr = vec.begin(),
428  vec_end = vec.end();
429  for ( ; vec_itr < vec_end; ++vec_itr)
430  *vec_itr = 0.0;
431  }
432  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, vectorTime);
433 
434  // Array
435  Teuchos::Array<double> a(arraySize);
436  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
437  {
439  a_itr = a.begin(),
440  a_end = a.end();
441  for ( ; a_itr < a_end; ++a_itr)
442  *a_itr = 0.0;
443  }
444  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, arrayTime);
445 
446  // vector/raw
447  const double vectorRatio = vectorTime / rawPtrTime;
448  outputter.outputField(vectorRatio);
449 
450  // Array/raw
451  const double arrayRatio = arrayTime / rawPtrTime;
452  outputter.outputField(arrayRatio);
453 
454  outputter.nextRow();
455 
456  arraySize *= 4;
457  finalArrayIterRatio = TEUCHOS_MIN(arrayRatio, finalArrayIterRatio);
458 
459  }
460 
461  out << "\n";
462  TEST_COMPARE( finalArrayIterRatio, <=, maxArrayIterRatio );
463  out << "\n";
464 
465 }
466 
467 
468 TEUCHOS_UNIT_TEST( ArrayView, iteratorOverhead )
469 {
470 
471  typedef Teuchos::TabularOutputter TO;
472 
473  const double relTestCost = 1e-4;
474 
475  const double numInnerLoops = relCpuSpeed / relTestCost;
476 
477  out << "\n"
478  << "Measuring the overhead of the ArrayView iterators relative to raw pointers.\n"
479  << "\n"
480  << "Number of loops = relCpuSpeed/relTestCost = "
481  << relCpuSpeed << "/" << relTestCost << " = " << numInnerLoops << "\n"
482  << "\n";
483 
484  TabularOutputter outputter(out);
485  outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
486  outputter.setFieldTypePrecision(TO::INT, intPrec);
487 
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);
493 
494  outputter.outputHeader();
495 
496  // Start out really big to make sure it fails if not set correctly!
497  double finalArrayViewIterRatio = 100000.0;
498 
499  Ordinal arraySize = minArraySize;
500  for (int test_case_k = 0;
501  test_case_k < maxLoopIters && arraySize <= maxArraySize;
502  ++test_case_k
503  )
504  {
505 
506  // array dim
507  outputter.outputField(arraySize);
508 
509  // num loops
510  const int numActualLoops =
511  TEUCHOS_MAX(
512  static_cast<int>(
513  (numInnerLoops / arraySize)
514  * std::log(static_cast<double>(arraySize+1))
515  ),
516  1
517  );
518  outputter.outputField(numActualLoops);
519 
520  std::vector<double> vec(arraySize);
521 
522  // raw ptr
523  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
524  {
525  double
526  *p_raw_itr = &vec[0],
527  *p_raw_end = &vec[0] + arraySize;
528  for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
529  *p_raw_itr = 0.0;
530  }
531  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
532 
533  // ArrayView
534  Teuchos::Array<double> a(arraySize);
536  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
537  {
539  av_itr = av.begin(),
540  av_end = av.end();
541  for ( ; av_itr < av_end ; ++av_itr)
542  *av_itr = 0.0;
543  }
544  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, arrayviewTime);
545 
546  // ArrayView/raw
547  const double arrayviewRatio = arrayviewTime / rawPtrTime;
548  outputter.outputField(arrayviewRatio);
549 
550  outputter.nextRow();
551 
552  arraySize *= 4;
553  finalArrayViewIterRatio = TEUCHOS_MIN(arrayviewRatio, finalArrayViewIterRatio);
554 
555  }
556 
557  out << "\n";
558  TEST_COMPARE( finalArrayViewIterRatio, <=, maxArrayIterRatio );
559  out << "\n";
560 
561 }
562 
563 
564 TEUCHOS_UNIT_TEST( ArrayRCP, iteratorOverhead )
565 {
566 
567  typedef Teuchos::TabularOutputter TO;
568 
569  const double relTestCost = 1e-4;
570 
571  const double numInnerLoops = relCpuSpeed / relTestCost;
572 
573  out << "\n"
574  << "Measuring the overhead of the ArrayRCP iterators relative to raw pointers.\n"
575  << "\n"
576  << "Number of loops = relCpuSpeed/relTestCost = "
577  << relCpuSpeed << "/" << relTestCost << " = " << numInnerLoops << "\n"
578  << "\n";
579 
580  TabularOutputter outputter(out);
581  outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
582  outputter.setFieldTypePrecision(TO::INT, intPrec);
583 
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);
589 
590  outputter.outputHeader();
591 
592  // Start out really big to make sure it fails if not set correctly!
593  double finalArrayRCPIterRatio = 100000.0;
594 
595  Ordinal arraySize = minArraySize;
596  for (int test_case_k = 0;
597  test_case_k < maxLoopIters && arraySize <= maxArraySize;
598  ++test_case_k
599  )
600  {
601 
602  // array dim
603  outputter.outputField(arraySize);
604 
605  // num loops
606  const int numActualLoops =
607  TEUCHOS_MAX(
608  static_cast<int>(
609  (numInnerLoops / arraySize)
610  * std::log(static_cast<double>(arraySize+1))
611  ),
612  1
613  );
614  outputter.outputField(numActualLoops);
615 
616  std::vector<double> vec(arraySize);
617 
618  // raw ptr
619  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
620  {
621  double
622  *p_raw_itr = &vec[0],
623  *p_raw_end = &vec[0] + arraySize;
624  for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
625  *p_raw_itr = 0.0;
626  }
627  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
628 
629  // ArrayRCP
630  Teuchos::ArrayRCP<double> ap = Teuchos::arcp<double>(arraySize);
631  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
632  {
634  ap_itr = ap.begin(),
635  ap_end = ap.end();
636  for ( ; ap_itr < ap_end; ++ap_itr)
637  *ap_itr = 0.0;
638  }
639  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, arrayviewTime);
640 
641  // ArrayRCP/raw
642  const double arrayviewRatio = arrayviewTime / rawPtrTime;
643  outputter.outputField(arrayviewRatio);
644 
645  outputter.nextRow();
646 
647  arraySize *= 4;
648  finalArrayRCPIterRatio = TEUCHOS_MIN(arrayviewRatio, finalArrayRCPIterRatio);
649 
650  }
651 
652  out << "\n";
653  TEST_COMPARE( finalArrayRCPIterRatio, <=, maxArrayIterRatio );
654  out << "\n";
655 
656 }
657 
658 
659 TEUCHOS_UNIT_TEST( ArrayRCP, selfIteratorOverhead )
660 {
661 
662  typedef Teuchos::TabularOutputter TO;
663 
664  const double relTestCost = 1e-4;
665 
666  const double numInnerLoops = relCpuSpeed / relTestCost;
667 
668  out << "\n"
669  << "Measuring the overhead of the ArrayRCP as a self iterataor relative to raw pointers.\n"
670  << "\n"
671  << "Number of loops = relCpuSpeed/relTestCost = "
672  << relCpuSpeed << "/" << relTestCost << " = " << numInnerLoops << "\n"
673  << "\n";
674 
675  TabularOutputter outputter(out);
676  outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
677  outputter.setFieldTypePrecision(TO::INT, intPrec);
678 
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);
684 
685  outputter.outputHeader();
686 
687  // Start out really big to make sure it fails if not set correctly!
688  double finalArrayRCPIterRatio = 100000.0;
689 
690  Ordinal arraySize = minArraySize;
691  for (int test_case_k = 0;
692  test_case_k < maxLoopIters && arraySize <= maxArraySize;
693  ++test_case_k
694  )
695  {
696 
697  // array dim
698  outputter.outputField(arraySize);
699 
700  // num loops
701  const int numActualLoops =
702  TEUCHOS_MAX(
703  static_cast<int>(
704  (numInnerLoops / arraySize)
705  * std::log(static_cast<double>(arraySize+1))
706  ),
707  1
708  );
709  outputter.outputField(numActualLoops);
710 
711  std::vector<double> vec(arraySize);
712 
713  // raw ptr
714  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
715  {
716  double
717  *p_raw_itr = &vec[0],
718  *p_raw_end = &vec[0] + arraySize;
719  for ( ; p_raw_itr < p_raw_end; ++p_raw_itr)
720  *p_raw_itr = 0.0;
721  }
722  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
723 
724  // ArrayRCP
725  Teuchos::ArrayRCP<double> ap = Teuchos::arcp<double>(arraySize);
726  TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
727  {
729  ap_itr = ap,
730  ap_end = ap + arraySize;
731  for ( ; ap_itr < ap_end; ++ap_itr)
732  *ap_itr = 0.0;
733  }
734  TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, arrayviewTime);
735 
736  // ArrayRCP/raw
737  const double arrayviewRatio = arrayviewTime / rawPtrTime;
738  outputter.outputField(arrayviewRatio);
739 
740  outputter.nextRow();
741 
742  arraySize *= 4;
743  finalArrayRCPIterRatio = TEUCHOS_MIN(arrayviewRatio, finalArrayRCPIterRatio);
744 
745  }
746 
747  out << "\n";
748  TEST_COMPARE( finalArrayRCPIterRatio, <=, maxArrayRCPSelfIterRatio );
749  out << "\n";
750 
751 }
752 
753 
754 } // namespace
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 = &#39;==&#39;, &#39;&gt;=&quot;, &quot;!=", etc).
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP&lt;Array&lt;T&gt; &gt; object as an ArrayRCP&lt;T&gt; 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.
Unit testing support.
#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.
Nonowning array view.
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.
TEUCHOS_STATIC_SETUP()
Reference-counted smart pointer for managing arrays.