/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ /* $Id: ImageAdd_nArray_Benchmark.cpp,v 1.4 2007/07/02 16:29:32 anton Exp $ Author(s): Ofri Sadowsky, Daniel Li Created on: 2007-07-01 (C) Copyright 2007-2007 Johns Hopkins University (JHU), All Rights Reserved. --- begin cisst license - do not edit --- This software is provided "as is" under an open source license, with no warranty. The complete license can be found in license.txt and http://www.cisst.org/cisst/license.txt. --- end cisst license --- */ #include #include #include #include #include #include #include #include #include #include using namespace std; /* define typedefs */ typedef int value_type; typedef vctDynamicNArray NArrayType; typedef vctDynamicNArray NArrayLowerDimType; int main() { /* create parent containers */ NArrayType::nsize_type parentContainerSize(80, 80, 80, 80); NArrayType parentContainer1; NArrayType parentContainer2; parentContainer1.SetSize( parentContainerSize ); parentContainer2.SetSize( parentContainerSize ); /* create an overlay dynamic vector for fast fill */ const unsigned int totalSize = parentContainer1.size(); vctDynamicVectorRef parentContainer1AsVector(totalSize, parentContainer1.Pointer()); vctDynamicVectorRef parentContainer2AsVector(totalSize, parentContainer2.Pointer()); /* create window overlay */ NArrayType::nsize_type windowOverlaySize(72, 72, 72, 72); NArrayType::nsize_type windowOverlayStart(2, 2, 2, 2); NArrayType::SubarrayRefType windowOverlay1 = parentContainer1.Subarray( windowOverlayStart, windowOverlaySize ); NArrayType::SubarrayRefType windowOverlay2 = parentContainer2.Subarray( windowOverlayStart, windowOverlaySize ); /* print configuration information */ cout << cmnPrintf( "parentContainerSize : %4d\n" "windowOverlaySize : %4d\n" "windowOverlayStart : %4d\n") << parentContainerSize << windowOverlaySize << windowOverlayStart; /* create sum container */ NArrayType sumContainer; sumContainer.SetSize( windowOverlaySize ); /* create timers */ osaStopwatch sumTimer, plusTimer; { std::cout << "Enter something and press to begin benchmark\n"; char dummy[5]; std::cin >> dummy; } cout << endl << "All times are in milliseconds. Times are cumulative." << endl << endl; cout << cmnPrintf(" %15s%15s\n") << "SumOf time" << "operator + time"; const unsigned int numIterations = 30; unsigned int i; for (i = 1; i <= numIterations; ++i) { /* fill with iterator */ vctRandom( parentContainer1AsVector, value_type(-20), value_type(20) ); vctRandom( parentContainer2AsVector, value_type(-20), value_type(20) ); /* sum */ sumTimer.Start(); sumContainer.SumOf( windowOverlay1, windowOverlay2 ); sumTimer.Stop(); plusTimer.Start(); sumContainer = windowOverlay1 + windowOverlay2; plusTimer.Stop(); cout << cmnPrintf("%5d%15d%15d\n") << i << sumTimer.GetCurrentRead() << plusTimer.GetCurrentRead(); cout << flush; } cout << endl; cout << cmnPrintf("%5s%15d%15d\n\n") << "TOTAL" << sumTimer.GetCurrentRead() << plusTimer.GetCurrentRead(); return 0; } // **************************************************************************** // Change History // **************************************************************************** // // $Log: ImageAdd_nArray_Benchmark.cpp,v $ // Revision 1.4 2007/07/02 16:29:32 anton // nArrayBenchmark example: Removed unused variables. // // Revision 1.3 2007/07/02 03:15:42 anton // nArrayBenchmark example: Added default header/footer. // // // ****************************************************************************