Teuchos Package Browser (Single Doxygen Collection) Version of the Day
RCP_Performance_UnitTests.cpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 //
00005 //                    Teuchos: Common Tools Package
00006 //                 Copyright (2004) Sandia Corporation
00007 //
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 //
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00026 //
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 #include "Teuchos_UnitTestHarness.hpp"
00032 #include "Teuchos_RCP.hpp"
00033 #include "Teuchos_TabularOutputter.hpp"
00034 
00035 #ifdef HAVE_TEUCHOS_BOOST
00036 #  include "boost/shared_ptr.hpp"
00037 #endif
00038 
00039 
00040 namespace {
00041 
00042 
00043 using Teuchos::null;
00044 using Teuchos::RCP;
00045 using Teuchos::rcp;
00046 using Teuchos::TabularOutputter;
00047 
00048 
00049 double relCpuSpeed = 1e-2;
00050 int maxArraySize = 10000;
00051 double maxRcpRawCreateDestroyRatio = 10.0;
00052 double maxRcpRawAdjustRefCountRatio = 100.0;
00053 double maxRcpSpAdjustRefCountRatio = 5.0;
00054 double maxRcpRawObjAccessRatio = 10.0;
00055 
00056 const int intPrec = 8;
00057 const int dblPrec = 6;
00058 
00059 
00060 TEUCHOS_STATIC_SETUP()
00061 {
00062   Teuchos::CommandLineProcessor &clp =
00063     Teuchos::UnitTestRepository::getCLP();
00064   clp.setOption(
00065     "rel-cpu-speed", &relCpuSpeed,
00066     "The relative speed of the CPU (higher means the machine runs faster)"
00067     );
00068   clp.setOption(
00069     "max-array-size", &maxArraySize,
00070     "The maximum size of the arrays created"
00071     );
00072   clp.setOption(
00073     "max-rcp-create-destroy-ratio", &maxRcpRawCreateDestroyRatio,
00074     "The ratio of the final CPU time ratio of creating and destroying"
00075     "std::vector<char>(size) objects wrapped in an RCP object versus"
00076     "using just raw new and delete."
00077     );
00078   clp.setOption(
00079     "max-rcp-raw-adjust-ref-count-ratio", &maxRcpRawAdjustRefCountRatio,
00080     "The ratio of the final CPU time ratio for adjusting the reference"
00081     "count of RCP objects versus a raw pointer."
00082     );
00083   clp.setOption(
00084     "max-rcp-sp-adjust-ref-count-ratio", &maxRcpSpAdjustRefCountRatio,
00085     "The ratio of the final CPU time ratio for adjusting the reference"
00086     "count of RCP objects versus boost::shared_ptr objects."
00087     );
00088   clp.setOption(
00089     "max-rcp-raw-obj-access-ratio", &maxRcpRawObjAccessRatio,
00090     "The ratio of the final CPU time ratio for accessing the object for RCP"
00091     "versus a raw pointer."
00092     );
00093 
00094 }
00095 
00096 
00097 template<typename T>
00098 struct DeleteDeleter {};
00099 
00100 
00101 TEUCHOS_UNIT_TEST( RCP, _sizeofObjects )
00102 {
00103   out << "\nPrinting the size the RCP and RCPNodeImpl objects ...\n";
00104   TEST_INEQUALITY_CONST(sizeof(bool), 0);
00105   TEST_INEQUALITY_CONST(sizeof(double), 0);
00106   TEST_INEQUALITY_CONST(sizeof(double*), 0);
00107   TEST_INEQUALITY_CONST(sizeof(std::vector<double>), 0);
00108   TEST_INEQUALITY_CONST(sizeof(Teuchos::RCPNode*), 0);
00109   TEST_INEQUALITY_CONST(sizeof(Teuchos::ERCPStrength), 0);
00110   TEST_INEQUALITY_CONST(sizeof(Teuchos::RCPNodeHandle), 0);
00111   TEST_INEQUALITY_CONST(sizeof(Teuchos::RCP<std::vector<double> >), 0);
00112   TEST_INEQUALITY_CONST(
00113     sizeof(Teuchos::RCPNodeTmpl<std::vector<double>,
00114       Teuchos::DeallocDelete<std::vector<double> > >),
00115     0);
00116 #ifdef HAVE_TEUCHOS_BOOST
00117   TEST_INEQUALITY_CONST(sizeof(boost::detail::shared_count), 0);
00118   TEST_INEQUALITY_CONST(sizeof(boost::shared_ptr<std::vector<double> >), 0);
00119   TEST_INEQUALITY_CONST(sizeof(boost::detail::sp_counted_impl_p<std::vector<double> >), 0);
00120   TEST_INEQUALITY_CONST(
00121     sizeof(boost::detail::sp_counted_impl_pd<std::vector<double>,
00122       DeleteDeleter<std::vector<double> > >),
00123     0);
00124 #endif
00125 }
00126 
00127 
00128 TEUCHOS_UNIT_TEST( RCP, createDestroyOverhead )
00129 {
00130 
00131   typedef Teuchos::TabularOutputter TO;
00132 
00133   const int maxLoopIters = 1000;
00134   const double relTestCost = 1e-3;
00135   const double numInnerLoops = relCpuSpeed / relTestCost;
00136 
00137   out << "\n"
00138       << "Messuring the overhead of creating and destorying objects of different sizes\n"
00139       << "using raw C++ pointers, shared_ptr, and using RCP.\n"
00140       << "\n"
00141       << "Number of loops = relCpuSpeed/relTestCost = "
00142       << relCpuSpeed << "/" << relTestCost << " = " << numInnerLoops << "\n"
00143       << "\n";
00144 
00145   TabularOutputter outputter(out);
00146   outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
00147   outputter.setFieldTypePrecision(TO::INT, intPrec);
00148 
00149   outputter.pushFieldSpec("obj size", TO::INT);
00150   outputter.pushFieldSpec("num loops", TO::INT);
00151   outputter.pushFieldSpec("raw", TO::DOUBLE);
00152 #ifdef HAVE_TEUCHOS_BOOST
00153   outputter.pushFieldSpec("shared_ptr", TO::DOUBLE);
00154 #endif
00155   outputter.pushFieldSpec("RCP", TO::DOUBLE);
00156 #ifdef HAVE_TEUCHOS_BOOST
00157   outputter.pushFieldSpec("shared_ptr/raw", TO::DOUBLE);
00158 #endif
00159   outputter.pushFieldSpec("RCP/raw", TO::DOUBLE);
00160 
00161   outputter.outputHeader();
00162 
00163   double finalRcpRawRatio = 100000.0;
00164 
00165   int arraySize = 1;
00166   for (int test_case_k = 0;
00167     test_case_k < maxLoopIters && arraySize <= maxArraySize;
00168     ++test_case_k
00169     )
00170   {
00171 
00172     // obj size
00173     outputter.outputField(arraySize);
00174 
00175     // num loops
00176     const int numActualLoops =
00177       TEUCHOS_MAX(
00178         static_cast<int>(
00179           (numInnerLoops / arraySize)
00180           * std::log(static_cast<double>(arraySize+1))
00181           ),
00182         1
00183         );
00184     outputter.outputField(numActualLoops);
00185 
00186     // raw
00187     {
00188       std::vector<std::vector<char>*> p_raw_vec(numActualLoops);
00189       int i = 0;
00190       TEUCHOS_START_PERF_OUTPUT_TIMER(outputter, numActualLoops)
00191       {
00192         p_raw_vec[i] = new std::vector<char>(arraySize, 1);
00193         delete p_raw_vec[i];
00194         ++i;
00195       }
00196     }
00197     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
00198     
00199 #ifdef HAVE_TEUCHOS_BOOST
00200     // shared_ptr
00201     {
00202       typedef boost::shared_ptr<std::vector<char> > shared_ptr_t;
00203       std::vector<shared_ptr_t > sp_vec(numActualLoops);
00204       int i = 0;
00205       TEUCHOS_START_PERF_OUTPUT_TIMER(outputter, numActualLoops)
00206       {
00207         sp_vec[i] = shared_ptr_t(new std::vector<char>(arraySize, 1));
00208         sp_vec[i].reset();
00209         ++i;
00210       }
00211     }
00212     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, spTime);
00213 #endif
00214 
00215     // RCP
00216     {
00217       std::vector<RCP<std::vector<char> > > p_vec(numActualLoops);
00218       int i = 0;
00219       TEUCHOS_START_PERF_OUTPUT_TIMER(outputter, numActualLoops)
00220       {
00221         p_vec[i] = rcp(new std::vector<char>(arraySize, 1));
00222         p_vec[i] = null;
00223       }
00224     }
00225     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rcpTime);
00226 
00227 #ifdef HAVE_TEUCHOS_BOOST
00228     // shared_ptr/rawPtr
00229     const double spRatio = spTime / rawPtrTime;
00230     outputter.outputField(spRatio);
00231 #endif
00232 
00233     // RCP/rawPtr
00234     const double rcpRatio = rcpTime / rawPtrTime;
00235     outputter.outputField(rcpRatio);
00236 
00237     outputter.nextRow();
00238     
00239     arraySize *= 4;
00240     finalRcpRawRatio = TEUCHOS_MIN(rcpRatio, finalRcpRawRatio);
00241 
00242   }
00243 
00244   out << "\n";
00245   TEST_COMPARE( finalRcpRawRatio, <=, maxRcpRawCreateDestroyRatio );
00246   out << "\n";
00247 
00248 }
00249 
00250 
00251 TEUCHOS_UNIT_TEST( RCP, referenceCountManipulationOverhead )
00252 {
00253 
00254   typedef Teuchos::TabularOutputter TO;
00255 
00256   const double relTestCost = 5e-3;
00257   const int maxLoopIters = 1000;
00258   const double numInnerLoops = relCpuSpeed / relTestCost;
00259 
00260   out << "\n"
00261       << "Messuring the overhead of incrementing and deincrementing the reference count\n"
00262       << "comparing RCP to raw pointer and boost::shared_ptr.\n"
00263       << "\n";
00264 
00265   TabularOutputter outputter(out);
00266   outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
00267   outputter.setFieldTypePrecision(TO::INT, intPrec);
00268 
00269   outputter.pushFieldSpec("array dim", TO::INT);
00270   outputter.pushFieldSpec("num loops", TO::INT);
00271   outputter.pushFieldSpec("raw", TO::DOUBLE);
00272   outputter.pushFieldSpec("shared_ptr", TO::DOUBLE);
00273   outputter.pushFieldSpec("RCP", TO::DOUBLE);
00274   outputter.pushFieldSpec("RCP/raw", TO::DOUBLE);
00275   outputter.pushFieldSpec("RCP/shared_ptr", TO::DOUBLE);
00276 
00277   outputter.outputHeader();
00278 
00279   double finalRcpRawRatio = 100000.0;
00280   double finalRcpSpRatio = 100000.0;
00281   int arraySize = 64;
00282 
00283   for (
00284     int test_case_k = 0;
00285     test_case_k < maxLoopIters && arraySize <= maxArraySize;
00286     ++test_case_k
00287     )
00288   {
00289 
00290     // array dim
00291     outputter.outputField(arraySize);
00292 
00293     // num loops
00294     const int numActualLoops =
00295       TEUCHOS_MAX(
00296         static_cast<int>(
00297           (numInnerLoops / arraySize)
00298           * std::log(static_cast<double>(arraySize+1))
00299           ),
00300         1
00301         );
00302     outputter.outputField(numActualLoops);
00303 
00304     // raw
00305     {
00306       char dummy_char = 'n';
00307       std::vector<char*> p_raw_vec(arraySize);
00308       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00309       {
00310         for (int i=0; i < arraySize; ++i) {
00311           p_raw_vec[i] = &dummy_char;
00312         }
00313       }
00314     }
00315     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
00316     
00317 #ifdef HAVE_TEUCHOS_BOOST
00318     // shared_ptr
00319     {
00320       typedef boost::shared_ptr<char> shared_ptr_t;
00321       shared_ptr_t sp(new char('n'));
00322       std::vector<shared_ptr_t> sp_vec(arraySize);
00323       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00324       {
00325         for (int i=0; i < arraySize; ++i) {
00326           sp_vec[i] = sp;
00327         }
00328       }
00329     }
00330     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, spTime);
00331 #else
00332     outputter.outputField("-");
00333 #endif
00334 
00335     // RCP
00336     {
00337       RCP<char> p(new char('n'));
00338       std::vector<RCP<char> > p_vec(arraySize);
00339       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00340       {
00341         for (int i=0; i < arraySize; ++i) {
00342           p_vec[i] = p;
00343           // NOTE: This assignment operation tests the copy constructor and
00344           // the swap function.  This calls both bind() and unbind()
00345           // underneath.
00346         }
00347       }
00348     }
00349     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rcpTime);
00350 
00351     // RCP/raw
00352     const double rcpRawRatio = rcpTime / rawPtrTime;
00353     finalRcpRawRatio = TEUCHOS_MIN(rcpRawRatio, finalRcpRawRatio);
00354     outputter.outputField(rcpRawRatio);
00355 
00356 #ifdef HAVE_TEUCHOS_BOOST
00357     // RCP/shared_ptr
00358     const double rcpSpRatio = rcpTime / spTime;
00359     finalRcpSpRatio = TEUCHOS_MIN(rcpSpRatio, finalRcpSpRatio);
00360     outputter.outputField(rcpSpRatio);
00361 #else
00362     outputter.outputField("-");
00363 #endif
00364 
00365     outputter.nextRow();
00366     
00367     arraySize *= 4;
00368 
00369   }
00370 
00371   out << "\n";
00372   TEST_COMPARE( finalRcpRawRatio, <=, maxRcpRawAdjustRefCountRatio );
00373 #ifdef HAVE_TEUCHOS_BOOST
00374   out << "\n";
00375   TEST_COMPARE( finalRcpSpRatio, <=, maxRcpSpAdjustRefCountRatio );
00376   out << "\n";
00377 #else
00378   (void)finalRcpSpRatio;
00379 #endif
00380   
00381 }
00382 
00383 
00384 TEUCHOS_UNIT_TEST( RCP, dereferenceOverhead )
00385 {
00386 
00387   typedef Teuchos::TabularOutputter TO;
00388 
00389   const double relTestCost = 1e-4;
00390   const int maxLoopIters = 1000;
00391   const double numInnerLoops = relCpuSpeed / relTestCost;
00392 
00393   out << "\n"
00394       << "Messuring the overhead of dereferencing RCP, shared_ptr and a raw pointer.\n"
00395       << "\n";
00396 
00397   TabularOutputter outputter(out);
00398   outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
00399   outputter.setFieldTypePrecision(TO::INT, intPrec);
00400 
00401   outputter.pushFieldSpec("array dim", TO::INT);
00402   outputter.pushFieldSpec("num loops", TO::INT);
00403   outputter.pushFieldSpec("raw", TO::DOUBLE);
00404   outputter.pushFieldSpec("shared_ptr", TO::DOUBLE);
00405   outputter.pushFieldSpec("RCP", TO::DOUBLE);
00406   outputter.pushFieldSpec("RCP/raw", TO::DOUBLE);
00407   outputter.pushFieldSpec("RCP/shared_ptr", TO::DOUBLE);
00408 
00409   outputter.outputHeader();
00410 
00411   double finalRcpRawRatio = 100000.0;
00412   int arraySize = 64;
00413   const int dummy_int_val = 1;
00414   int overall_dummy_int_out = 0;
00415   
00416 
00417   for (
00418     int test_case_k = 0;
00419     test_case_k < maxLoopIters && arraySize <= maxArraySize;
00420     ++test_case_k
00421     )
00422   {
00423 
00424     // array dim
00425     outputter.outputField(arraySize);
00426 
00427     // num loops
00428     const int numActualLoops =
00429       TEUCHOS_MAX(
00430         static_cast<int>(
00431           (numInnerLoops / arraySize)
00432           * std::log(static_cast<double>(arraySize+1))
00433           ),
00434         1
00435         );
00436     outputter.outputField(numActualLoops);
00437 
00438     int dummy_int_out = 0;
00439 
00440     // raw
00441     {
00442       int dummy_int = dummy_int_val;
00443       std::vector<int*> p_raw_vec(arraySize);
00444       for (int i=0; i < arraySize; ++i) {
00445         p_raw_vec[i] = &dummy_int;
00446       }
00447       dummy_int_out = 0;
00448       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00449       {
00450         for (int i=0; i < arraySize; ++i) {
00451           dummy_int_out += *p_raw_vec[i];
00452         }
00453       }
00454     }
00455     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
00456     overall_dummy_int_out += dummy_int_out;
00457     
00458     // shared_ptr
00459 #ifdef HAVE_TEUCHOS_BOOST
00460     {
00461       typedef boost::shared_ptr<int> shared_ptr_t;
00462       shared_ptr_t sp(new int(dummy_int_val));
00463       std::vector<shared_ptr_t> sp_vec(arraySize);
00464       for (int i=0; i < arraySize; ++i) {
00465         sp_vec[i] = sp;
00466       }
00467       dummy_int_out = 0;
00468       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00469       {
00470         for (int i=0; i < arraySize; ++i) {
00471           dummy_int_out += *sp_vec[i];
00472         }
00473       }
00474     }
00475     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, spTime);
00476     overall_dummy_int_out += dummy_int_out;
00477 #else
00478     outputter.outputField("-");
00479 #endif
00480 
00481     // RCP
00482     {
00483       RCP<int> p(new int(dummy_int_val));
00484       std::vector<RCP<int> > p_vec(arraySize);
00485       for (int i=0; i < arraySize; ++i) {
00486         p_vec[i] = p;
00487       }
00488       dummy_int_out = 0;
00489       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00490       {
00491         for (int i=0; i < arraySize; ++i) {
00492           dummy_int_out += *p_vec[i];
00493         }
00494       }
00495     }
00496     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rcpTime);
00497     overall_dummy_int_out += dummy_int_out;
00498 
00499     // RCP/raw
00500     const double rcpRawRatio = rcpTime / rawPtrTime;
00501     finalRcpRawRatio = TEUCHOS_MIN(rcpRawRatio, finalRcpRawRatio);
00502     outputter.outputField(rcpRawRatio);
00503 
00504 #ifdef HAVE_TEUCHOS_BOOST
00505     // RCP/shared_ptr
00506     const double rcpSpRatio = rcpTime / spTime;
00507     outputter.outputField(rcpSpRatio);
00508 #else
00509     outputter.outputField("-");
00510 #endif
00511 
00512     outputter.nextRow();
00513     
00514     arraySize *= 4;
00515 
00516   }
00517 
00518   out << "\n";
00519   TEST_COMPARE( finalRcpRawRatio, <=, maxRcpRawObjAccessRatio );
00520   out << "\n";
00521 
00522   // This silly varible must be accumulated or compilers like MSVC++ will
00523   // optimize away the loops!
00524   if (overall_dummy_int_out == 0)
00525     success = false;
00526   
00527 }
00528 
00529 
00530 struct SomeStruct {
00531   SomeStruct(int member_in) : member(member_in) {}
00532   int member;
00533 };
00534 
00535 
00536 TEUCHOS_UNIT_TEST( RCP, memberAccessOverhead )
00537 {
00538 
00539   typedef Teuchos::TabularOutputter TO;
00540 
00541   const double relTestCost = 1e-4;
00542   const int maxLoopIters = 1000;
00543   const double numInnerLoops = relCpuSpeed / relTestCost;
00544 
00545   out << "\n"
00546       << "Messuring the overhead of dereferencing RCP, shared_ptr and a raw pointer.\n"
00547       << "\n";
00548 
00549   TabularOutputter outputter(out);
00550   outputter.setFieldTypePrecision(TO::DOUBLE, dblPrec);
00551   outputter.setFieldTypePrecision(TO::INT, intPrec);
00552 
00553   outputter.pushFieldSpec("array dim", TO::INT);
00554   outputter.pushFieldSpec("num loops", TO::INT);
00555   outputter.pushFieldSpec("raw", TO::DOUBLE);
00556   outputter.pushFieldSpec("shared_ptr", TO::DOUBLE);
00557   outputter.pushFieldSpec("RCP", TO::DOUBLE);
00558   outputter.pushFieldSpec("RCP/raw", TO::DOUBLE);
00559   outputter.pushFieldSpec("RCP/shared_ptr", TO::DOUBLE);
00560 
00561   outputter.outputHeader();
00562 
00563   double finalRcpRawRatio = 100000.0;
00564   int arraySize = 64;
00565   const int dummy_int_val = 1;
00566   int overall_dummy_int_out = 0;
00567 
00568   for (
00569     int test_case_k = 0;
00570     test_case_k < maxLoopIters && arraySize <= maxArraySize;
00571     ++test_case_k
00572     )
00573   {
00574 
00575     // array dim
00576     outputter.outputField(arraySize);
00577 
00578     // num loops
00579     const int numActualLoops =
00580       TEUCHOS_MAX(
00581         static_cast<int>(
00582           (numInnerLoops / arraySize)
00583           * std::log(static_cast<double>(arraySize+1))
00584           ),
00585         1
00586         );
00587     outputter.outputField(numActualLoops);
00588 
00589     int dummy_int_out = 0;
00590 
00591     // raw
00592     {
00593       SomeStruct dummy_SomeStruct(dummy_int_val);
00594       std::vector<SomeStruct*> p_raw_vec(arraySize);
00595       for (int i=0; i < arraySize; ++i) {
00596         p_raw_vec[i] = &dummy_SomeStruct;
00597       }
00598       dummy_int_out = 0;
00599       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00600       {
00601         for (int i=0; i < arraySize; ++i) {
00602           dummy_int_out += p_raw_vec[i]->member;
00603         }
00604       }
00605     }
00606     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rawPtrTime);
00607     overall_dummy_int_out += dummy_int_out;
00608     
00609     // shared_ptr
00610 #ifdef HAVE_TEUCHOS_BOOST
00611     {
00612       typedef boost::shared_ptr<SomeStruct> shared_ptr_t;
00613       shared_ptr_t sp(new SomeStruct(dummy_int_val));
00614       std::vector<shared_ptr_t> sp_vec(arraySize);
00615       for (int i=0; i < arraySize; ++i) {
00616         sp_vec[i] = sp;
00617       }
00618       dummy_int_out = 0;
00619       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00620       {
00621         for (int i=0; i < arraySize; ++i) {
00622           dummy_int_out += sp_vec[i]->member;
00623         }
00624       }
00625     }
00626     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, spTime);
00627     overall_dummy_int_out += dummy_int_out;
00628 #else
00629     outputter.outputField("-");
00630 #endif
00631 
00632     // RCP
00633     {
00634       RCP<SomeStruct> p(new SomeStruct(dummy_int_val));
00635       std::vector<RCP<SomeStruct> > p_vec(arraySize);
00636       for (int i=0; i < arraySize; ++i) {
00637         p_vec[i] = p;
00638       }
00639       dummy_int_out = 0;
00640       TEUCHOS_START_PERF_OUTPUT_TIMER_INNERLOOP(outputter, numActualLoops, arraySize)
00641       {
00642         for (int i=0; i < arraySize; ++i) {
00643           dummy_int_out += p_vec[i]->member;
00644         }
00645       }
00646     }
00647     TEUCHOS_END_PERF_OUTPUT_TIMER(outputter, rcpTime);
00648     overall_dummy_int_out += dummy_int_out;
00649 
00650     // RCP/raw
00651     const double rcpRawRatio = rcpTime / rawPtrTime;
00652     finalRcpRawRatio = TEUCHOS_MIN(rcpRawRatio, finalRcpRawRatio);
00653     outputter.outputField(rcpRawRatio);
00654 
00655 #ifdef HAVE_TEUCHOS_BOOST
00656     // RCP/shared_ptr
00657     const double rcpSpRatio = rcpTime / spTime;
00658     outputter.outputField(rcpSpRatio);
00659 #else
00660     outputter.outputField("-");
00661 #endif
00662 
00663     outputter.nextRow();
00664     
00665     arraySize *= 4;
00666 
00667   }
00668 
00669   out << "\n";
00670   TEST_COMPARE( finalRcpRawRatio, <=, maxRcpRawObjAccessRatio );
00671   out << "\n";
00672 
00673   // This silly varible must be accumulated or compilers like MSVC++ will
00674   // optimize away the loops!
00675   if (overall_dummy_int_out == 0)
00676     success = false;
00677   
00678 }
00679 
00680 
00681 
00682 
00683 
00684 
00685 
00686 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines