Commit 89254b45 authored by Anton Bukov's avatar Anton Bukov

Prettify benchmark code

parent d2dff508
...@@ -61,10 +61,8 @@ static void BM_CppCode (benchmark::State& state) ...@@ -61,10 +61,8 @@ static void BM_CppCode (benchmark::State& state)
while (state.KeepRunning () ) { while (state.KeepRunning () ) {
double sum = 0; double sum = 0;
int count = 0; int count = 0;
for (unsigned i = 0; i < vecCpp.size(); i++) for (unsigned i = 0; i < vecCpp.size(); i++) {
{ if (vecCpp[i] % 2 == 1) {
if (vecCpp[i] % 2 == 1)
{
sum += vecCpp[i]; sum += vecCpp[i];
count++; count++;
} }
...@@ -72,9 +70,11 @@ static void BM_CppCode (benchmark::State& state) ...@@ -72,9 +70,11 @@ static void BM_CppCode (benchmark::State& state)
double avgValue = sum / count; double avgValue = sum / count;
double stdSum = 0; double stdSum = 0;
for (unsigned i = 0; i < vecCpp.size(); i++) for (unsigned i = 0; i < vecCpp.size(); i++) {
if (vecCpp[i] % 2 == 1) if (vecCpp[i] % 2 == 1) {
stdSum += (vecCpp[i] - avgValue)*(vecCpp[i] - avgValue); stdSum += (vecCpp[i] - avgValue) * (vecCpp[i] - avgValue);
}
}
double stdValue = stdSum / count; double stdValue = stdSum / count;
// It's no test, instead it's avoiding skip of calculation through optimization. // It's no test, instead it's avoiding skip of calculation through optimization.
...@@ -93,10 +93,8 @@ static void BM_CppIterCode (benchmark::State& state) ...@@ -93,10 +93,8 @@ static void BM_CppIterCode (benchmark::State& state)
while (state.KeepRunning () ) { while (state.KeepRunning () ) {
double sum = 0; double sum = 0;
int count = 0; int count = 0;
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it) for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it) {
{ if (*it % 2 == 1) {
if (*it % 2 == 1)
{
sum += *it; sum += *it;
count++; count++;
} }
...@@ -104,9 +102,11 @@ static void BM_CppIterCode (benchmark::State& state) ...@@ -104,9 +102,11 @@ static void BM_CppIterCode (benchmark::State& state)
double avgValue = sum / count; double avgValue = sum / count;
double stdSum = 0; double stdSum = 0;
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it) for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it) {
if (*it % 2 == 1) if (*it % 2 == 1) {
stdSum += (*it - avgValue)*(*it - avgValue); stdSum += (*it - avgValue) * (*it - avgValue);
}
}
double stdValue = stdSum / count; double stdValue = stdSum / count;
// It's no test, instead it's avoiding skip of calculation through optimization. // It's no test, instead it's avoiding skip of calculation through optimization.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment