00001 #ifndef __HAYAI_TESTRESULT 00002 #define __HAYAI_TESTRESULT 00003 #include <vector> 00004 #include <stdexcept> 00005 #include <limits> 00006 00007 #include "hayai/hayai_clock.hpp" 00008 00009 00010 namespace hayai 00011 { 00013 00015 struct TestResult 00016 { 00017 public: 00019 00022 TestResult(const std::vector<uint64_t>& runTimes, 00023 std::size_t iterations) 00024 : _runTimes(runTimes), 00025 _iterations(iterations), 00026 _timeTotal(0), 00027 _timeRunMin(std::numeric_limits<uint64_t>::max()), 00028 _timeRunMax(std::numeric_limits<uint64_t>::min()) 00029 { 00030 // Summarize under the assumption of values being accessed more 00031 // than once. 00032 std::vector<uint64_t>::iterator runIt = _runTimes.begin(); 00033 00034 while (runIt != _runTimes.end()) 00035 { 00036 const uint64_t run = *runIt; 00037 00038 _timeTotal += run; 00039 00040 if ((runIt == _runTimes.begin()) || (run > _timeRunMax)) 00041 { 00042 _timeRunMax = run; 00043 } 00044 00045 if ((runIt == _runTimes.begin()) || (run < _timeRunMin)) 00046 { 00047 _timeRunMin = run; 00048 } 00049 00050 ++runIt; 00051 } 00052 } 00053 00054 00056 inline double TimeTotal() const 00057 { 00058 return double(_timeTotal); 00059 } 00060 00061 00063 inline const std::vector<uint64_t>& RunTimes() const 00064 { 00065 return _runTimes; 00066 } 00067 00068 00070 inline double RunTimeAverage() const 00071 { 00072 return double(_timeTotal) / double(_runTimes.size()); 00073 } 00074 00075 00077 inline double RunTimeMaximum() const 00078 { 00079 return double(_timeRunMax); 00080 } 00081 00082 00084 inline double RunTimeMinimum() const 00085 { 00086 return double(_timeRunMin); 00087 } 00088 00089 00091 inline double RunsPerSecondAverage() const 00092 { 00093 return 1000000000.0 / RunTimeAverage(); 00094 } 00095 00096 00098 inline double RunsPerSecondMaximum() const 00099 { 00100 return 1000000000.0 / _timeRunMin; 00101 } 00102 00103 00105 inline double RunsPerSecondMinimum() const 00106 { 00107 return 1000000000.0 / _timeRunMax; 00108 } 00109 00110 00112 inline double IterationTimeAverage() const 00113 { 00114 return RunTimeAverage() / double(_iterations); 00115 } 00116 00117 00119 inline double IterationTimeMinimum() const 00120 { 00121 return _timeRunMin / double(_iterations); 00122 } 00123 00124 00126 inline double IterationTimeMaximum() const 00127 { 00128 return _timeRunMax / double(_iterations); 00129 } 00130 00131 00133 inline double IterationsPerSecondAverage() const 00134 { 00135 return 1000000000.0 / IterationTimeAverage(); 00136 } 00137 00138 00140 inline double IterationsPerSecondMinimum() const 00141 { 00142 return 1000000000.0 / IterationTimeMaximum(); 00143 } 00144 00145 00147 inline double IterationsPerSecondMaximum() const 00148 { 00149 return 1000000000.0 / IterationTimeMinimum(); 00150 } 00151 private: 00152 std::vector<uint64_t> _runTimes; 00153 std::size_t _iterations; 00154 uint64_t _timeTotal; 00155 uint64_t _timeRunMin; 00156 uint64_t _timeRunMax; 00157 }; 00158 } 00159 #endif