Skip to content

Commit

Permalink
Updates based on review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarathnandu committed Oct 28, 2024
1 parent 31e2863 commit 8845c14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
33 changes: 17 additions & 16 deletions examples/common/utility/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,12 @@ class measurements {
}
measurements(int iterations) {
_time_intervals.reserve(iterations);
clear();
}
void clear() {
_time_intervals.clear();
}
void start() {

inline void start() {
_startTime = std::chrono::steady_clock::now();
}
void stop() {
inline void stop() {
auto _endTime = std::chrono::steady_clock::now();
// store the end time and start time
_time_intervals.push_back(std::make_pair(_startTime, _endTime));
Expand All @@ -388,21 +385,25 @@ class measurements {
auto total_duration = std::accumulate(
_time_intervals.begin(),
_time_intervals.end(),
0, // Start with 0 count
0, // Start with 0 count
[](long long total, const std::pair<time_point, time_point>& interval) {
// Compute the difference and add it to the total
return total + std::chrono::duration_cast<std::chrono::microseconds>(interval.second - interval.first).count();
}
);
return total + std::chrono::duration_cast<std::chrono::microseconds>(
interval.second - interval.first)
.count();
});
long long averageTimePerFrame = total_duration / _time_intervals.size();
long long sumOfSquareDiff = 0;
std::for_each(_time_intervals.begin(),
_time_intervals.end(),
[&](const std::pair<time_point, time_point>& interval) {
long long duration = std::chrono::duration_cast<std::chrono::microseconds>(interval.second - interval.first).count();
long long diff = duration - averageTimePerFrame;
sumOfSquareDiff += diff * diff;
});
[&](const std::pair<time_point, time_point>& interval) {
long long duration =
std::chrono::duration_cast<std::chrono::microseconds>(
interval.second - interval.first)
.count();
long long diff = duration - averageTimePerFrame;
sumOfSquareDiff += diff * diff;
});
double stdDev = std::sqrt(sumOfSquareDiff / _time_intervals.size());
double relError = 100 * (stdDev / averageTimePerFrame);
return relError;
Expand All @@ -411,7 +412,7 @@ class measurements {
private:
using time_point = std::chrono::steady_clock::time_point;
time_point _startTime;
std::vector< std::pair<time_point, time_point> > _time_intervals;
std::vector<std::pair<time_point, time_point>> _time_intervals;
};

namespace internal {
Expand Down
1 change: 1 addition & 0 deletions examples/parallel_for/seismic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ int main(int argc, char *argv[]) {
std::cout << "Substituting 1000 for unlimited frames because not running interactively"
<< "\n";
}
// TODO : Extend utility::cli_argument_pack() toallow specifying the default value.
if (options.numberofIterations == 0) {
options.numberofIterations = 10;
std::cout << "Setting the number of iterations = 10 default"
Expand Down

0 comments on commit 8845c14

Please sign in to comment.