X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/0c55251c3227ee5608f07d61bf4c1392b4985c72..3969d4ebdc78d21108c2d9e38875d5717eb36f53:/main.cpp diff --git a/main.cpp b/main.cpp index 8a23727..907869e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,7 @@ +#include #include #include +#include #include #include #include @@ -87,16 +89,19 @@ static void check_for_lost_load() static void compute_load_imbalance() { + using std::tr1::bind; + using std::tr1::placeholders::_1; + unsigned n = loads.size(); load_avg = std::accumulate(loads.begin(), loads.end(), 0.0) / n; - double variance = 0.0; - double epsilon = 0.0; - for (unsigned i = 0 ; i < n ; ++i) { - double diff = loads[i] - load_avg; - variance += diff * diff; - epsilon += diff; - } - variance = (variance - (epsilon * epsilon) / n) / n; + + std::vector diff(loads); + std::transform(diff.begin(), diff.end(), diff.begin(), + bind(std::minus(), _1, load_avg)); + double epsilon = std::accumulate(diff.begin(), diff.end(), 0.0); + double square_sum = std::inner_product(diff.begin(), diff.end(), + diff.begin(), 0.0); + double variance = (square_sum - (epsilon * epsilon) / n) / n; load_stddev = sqrt(variance); }