Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston committed Aug 9, 2024
1 parent 42f459f commit 1f4c0a2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/util/Sleeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Sleeper.hpp"

#include <chrono>
#include <cmath>

#if defined(_WIN32)

Expand Down Expand Up @@ -117,16 +118,16 @@ namespace util {
auto end = std::chrono::steady_clock::now();

// Update the idle sleep accuracy estimate using Welford's method
auto actual_sleep_time = end - start;
const auto actual_sleep_time = end - start;

double sleep_error =
const double sleep_error =
duration_cast<duration<double, std::nano>>(actual_sleep_time - target_sleep_time).count();
double delta = sleep_error - mean;
const double delta = sleep_error - mean;

count = count + 1;
mean = mean + (delta / count);
double delta2 = sleep_error - mean;
m2 = m2 + delta * delta2;
count = count + 1;
mean = mean + (delta / count);
const double delta2 = sleep_error - mean;
m2 = m2 + delta * delta2;

// Sleep accuracy with 3 standard deviations of the mean for a 99.7% confidence interval
sleep_accuracy = nanoseconds(std::lround(std::sqrt(m2 / count) * 3.0));
Expand Down

0 comments on commit 1f4c0a2

Please sign in to comment.