/* -*- 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: Subarray_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 container */ NArrayType::nsize_type parentContainerSize(93, 94, 95, 96); NArrayType parentContainer; parentContainer.SetSize( parentContainerSize ); /* create an overlay dynamic vector for fast fill */ const unsigned int totalSize = parentContainer.size(); vctDynamicVectorRef parentContainerAsVector(totalSize, parentContainer.Pointer()); /* create window overlay */ NArrayType::nsize_type windowOverlaySize(71, 72, 73, 74); NArrayType::nsize_type windowOverlayStart(16, 16, 16, 16); NArrayType::SubarrayRefType windowOverlay = parentContainer.Subarray( windowOverlayStart, windowOverlaySize ); /* create slice overlay */ const unsigned int sliceDimensionIndex = 2; const unsigned int sliceSelectionIndex = 64; NArrayType::SliceRefType sliceOverlay = parentContainer.Slice(sliceDimensionIndex, sliceSelectionIndex); /* create permutation overlay */ NArrayType::ndimension_type permuteDimensionOrder(3, 1, 2, 0); NArrayType::PermutationRefType permuteOverlay = parentContainer.Permute( permuteDimensionOrder ); /* print configuration information */ cout << cmnPrintf( "parentContainerSize : %4d\n" "windowOverlaySize : %4d\n" "windowOverlayStart : %4d\n" "sliceParameters : %4d %4d\n" "permutationOrder : %4d\n") << parentContainerSize << windowOverlaySize << windowOverlayStart << sliceDimensionIndex << sliceSelectionIndex << permuteDimensionOrder; /* create window container */ NArrayType windowContainer; windowContainer.SetSize( windowOverlay.sizes() ); /* create slice container */ NArrayLowerDimType sliceContainer; sliceContainer.SetSize( sliceOverlay.sizes() ); /* create permutation container */ NArrayType permuteContainer; permuteContainer.SetSize( permuteOverlay.sizes() ); /* create iterators */ NArrayType::iterator parentContainerIter; /* create timers */ osaStopwatch fillTimer, windowTimer, sliceTimer, permuteTimer; { std::cout << "Enter something and press to begin benchmark\n"; char dummy[5]; std::cin >> dummy; } cout << endl << "All times are in milliseconds" << endl << endl; cout << cmnPrintf("%20s%15s%15s%15s\n") << "Fill time" << "Window time" << "Slice time" << "Permute time"; const unsigned int numIterations = 30; unsigned int i; for (i = 1; i <= numIterations; ++i) { if (0) { fillTimer.Reset(); windowTimer.Reset(); sliceTimer.Reset(); permuteTimer.Reset(); } /* fill with iterator */ fillTimer.Start(); vctRandom(parentContainerAsVector, value_type(-20), value_type(20)); fillTimer.Stop(); /* window */ windowTimer.Start(); windowContainer.Assign( windowOverlay ); windowTimer.Stop(); /* slice */ sliceTimer.Start(); sliceContainer.Assign( sliceOverlay ); sliceTimer.Stop(); /* permute */ permuteTimer.Start(); permuteContainer.Assign( permuteOverlay ); permuteTimer.Stop(); cout << cmnPrintf("%5d%15d%15d%15d%15d\n") << i << fillTimer.GetCurrentRead() << windowTimer.GetCurrentRead() << sliceTimer.GetCurrentRead() << permuteTimer.GetCurrentRead(); cout << flush; } cout << endl; cout << cmnPrintf("%5s%15d%15d%15d%15d\n\n") << "TOTAL" << fillTimer.GetCurrentRead() << windowTimer.GetCurrentRead() << sliceTimer.GetCurrentRead() << permuteTimer.GetCurrentRead(); return 0; } // **************************************************************************** // Change History // **************************************************************************** // // $Log: Subarray_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. // // // ****************************************************************************