Skip to content

Commit f2d5c3a

Browse files
committed
#58 Fixed iterations on simple test cases.
The update to v2.0.0 improved the way experiment values and units were implemented. However, there was an oversight in that if these more complex features were not used, only a single iteration of the code under test was executed. Minor documentation updates were also performed.
1 parent e16eed8 commit f2d5c3a

File tree

12 files changed

+43
-36
lines changed

12 files changed

+43
-36
lines changed

experiments/DemoSimple/DemoSimple.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@ std::uniform_int_distribution<int> UniformDistribution(0, 1024);
2121
///
2222
/// Interestingly, taking the sin of a constant number here resulted in a
2323
/// great deal of optimization in clang and gcc.
24-
BASELINE(DemoSimple, Baseline, 10, 1000000)
24+
BASELINE(DemoSimple, Baseline, 30, 1000000)
2525
{
26-
celero::DoNotOptimizeAway(static_cast<float>(sin(UniformDistribution(RandomDevice))));
26+
celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(UniformDistribution(RandomDevice), 3.14159265))));
2727
}
2828

29-
/// Run a test consisting of 1 sample of 710000 operations per measurement.
29+
/// Run a test consisting of 1 sample of 710000 iterations per measurement.
3030
/// There are not enough samples here to likely get a meaningful result.
3131
BENCHMARK(DemoSimple, Complex1, 1, 710000)
3232
{
3333
celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(UniformDistribution(RandomDevice), 3.14159265))));
3434
}
3535

36-
/// Run a test consisting of 30 samples of 710000 operations per measurement.
36+
/// Run a test consisting of 30 samples of 710000 iterations per measurement.
3737
/// There are not enough samples here to get a reasonable measurement
3838
/// It should get a Basline number lower than the previous test.
3939
BENCHMARK(DemoSimple, Complex2, 30, 710000)
4040
{
4141
celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(UniformDistribution(RandomDevice), 3.14159265))));
4242
}
4343

44-
/// Run a test consisting of 60 samples of 710000 operations per measurement.
44+
/// Run a test consisting of 60 samples of 710000 iterations per measurement.
4545
/// There are not enough samples here to get a reasonable measurement
4646
/// It should get a Basline number lower than the previous test.
4747
BENCHMARK(DemoSimple, Complex3, 60, 710000)
4848
{
4949
celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(UniformDistribution(RandomDevice), 3.14159265))));
5050
}
5151

52-
/// Run a manual test consisting of 60 samples of 7100000 operations per measurement.
52+
/// Run a test consisting of 60 samples of 7100000 iterations per measurement.
5353
/// Samples here are much large and there are more of them. Expect a better answer here.
5454
/*
5555
BENCHMARK(DemoSimple, Complex4, 600, 20000000)

experiments/DemoSimpleJUnit/DemoSimpleJUnit.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
CELERO_MAIN
1313

1414
/// Run an automatic baseline.
15-
/// Celero will help make sure enough samples are taken to get a reasonable measurement
1615
/// In reality, all of the "Complex" cases take the same amount of time to run.
1716
/// The difference in the results is a product of measurement error.
1817
BASELINE(DemoSimple, Baseline, 1, 7100000)
@@ -27,15 +26,13 @@ BENCHMARK_TEST(DemoSimple, Complex1, 1, 7100000, 1.0)
2726
celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(rand(), 3.14159265))));
2827
}
2928

30-
/// Run a manual test consisting of 1 sample of 7100000 operations per measurement.
31-
/// Celero will help make sure enough samples are taken to get a reasonable measurement
29+
/// Run a manual test consisting of 1 sample of 7100000 iterations per measurement.
3230
BENCHMARK_TEST(DemoSimple, Complex2, 1, 7100000, 3.71)
3331
{
3432
celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(rand(), 3.14159265))));
3533
}
3634

37-
/// Run a manual test consisting of 60 samples of 7100000 operations per measurement.
38-
/// Celero will help make sure enough samples are taken to get a reasonable measurement
35+
/// Run a manual test consisting of 60 samples of 7100000 iterations per measurement.
3936
BENCHMARK_TEST(DemoSimple, Complex3, 60, 7100000, 5.0)
4037
{
4138
celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(rand(), 3.14159265))));

experiments/DemoTransform/DemoTransform.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,31 @@ class DemoTransformFixture : public celero::TestFixture
9494
int arraySize;
9595
};
9696

97+
#include <iostream>
98+
9799
// For a baseline, I'll chose Bubble Sort.
98100
BASELINE_F(DemoTransform, ForLoop, DemoTransformFixture, 30, 10000)
99101
{
102+
static int iterationCount = 0;
100103
for(int i = 0; i < this->arraySize; i++)
101104
{
102105
this->arrayOut[i] = this->arrayIn[i] * DemoTransformFixture::Multiple;
103106
}
107+
iterationCount++;
108+
if(iterationCount%1000== 0) std::cout << "Baseline " << iterationCount << std::endl;
109+
104110
}
105111

106112
// BASELINE_FIXED_F(DemoTransform, FixedTime, DemoTransformFixture, 30, 10000, 100)
107113
// { }
108114

109115
BENCHMARK_F(DemoTransform, StdTransform, DemoTransformFixture, 30, 10000)
110116
{
117+
static int iterationCount = 0;
111118
std::transform(this->arrayIn.begin(), this->arrayIn.end(), this->arrayOut.begin(), std::bind1st(std::multiplies<int>(), DemoTransformFixture::Multiple));
119+
120+
iterationCount++;
121+
if(iterationCount%1000== 0) std::cout << "Benchmark " << iterationCount << std::endl;
112122
}
113123

114124
BENCHMARK_F(DemoTransform, StdTransformLambda, DemoTransformFixture, 30, 10000)

include/celero/Celero.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@
2020
/// See the License for the specific language governing permissions and
2121
/// limitations under the License.
2222
///
23-
/// Ideas from Nick Brunn's Hayai (https://github.com/nickbruun/hayai) were used and I likely owe him a beer.
24-
///
25-
/// Special thanks to the band "3" for providing the development soundtrack.
23+
/// Special thanks to the bands "3" and "Coheed and Cambria" for providing the development soundtrack.
2624
///
2725
/// "Iterations" refers to how many loops of the test function are measured as a time.
2826
/// For very fast code, many iterations would help amoratize measurement error.
2927
///
30-
/// "Samples" refers to how many sets of "Ops" will be performed. Each "sample" is
31-
/// a single measurement. Set to 0 to have Celero decide how many samples are required
32-
/// for a minimally significant answer.
28+
/// "Samples" refers to how many sets of "Iterations" will be performed. Each "sample" is
29+
/// a single measurement.
3330
///
3431
/// It is highly encouraged to only run this code compiled in a "Release" mode to use all available optimizations.
3532
///

include/celero/Result.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,23 @@ namespace celero
8181
uint64_t getRunTime() const;
8282

8383
///
84-
/// \brief Get the number of computed microseconds per operation.
84+
/// \brief Get the number of computed microseconds per iteration (i.e. a single call to the code under test.)
8585
///
86-
/// An operation is defined as one operation of one run.
86+
/// A call is defined as one iteration of one execution of the code under test.
8787
///
8888
double getUsPerCall() const;
8989

9090
///
91-
/// \brief Get the number of computer operations per second.
91+
/// \brief Get the number of times the code under test could be called per second.
9292
///
93-
/// An operation is defined as one operation of one run.
93+
/// A call is defined as one iteration of one execution of the code under test.
9494
///
95-
double getOpsPerSecond() const;
95+
double getCallsPerSecond() const;
9696

9797
///
9898
/// \brief Get the processing speed in units per second.
9999
///
100-
/// An operation is defined as one operation of one run.
100+
/// A call is defined as one iteration of one execution of the code under test.
101101
///
102102
double getUnitsPerSecond() const;
103103

src/Experiment.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ size_t Experiment::getResultSize()
286286
{
287287
if(this->pimpl->results.empty() == true)
288288
{
289-
this->pimpl->results.push_back(std::make_shared<Result>(this));
289+
auto defaultResult = std::make_shared<Result>(this);
290+
defaultResult->setProblemSpaceValue(0, 1.0, this->getIterations());
291+
this->pimpl->results.push_back(defaultResult);
290292
}
291293

292294
return this->pimpl->results.size();

src/Print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void celero::print::TableResult(std::shared_ptr<Result> x)
217217

218218
std::cout << PrintColumn(x->getBaselineMeasurement())
219219
<< PrintColumn(x->getUsPerCall())
220-
<< PrintColumn(x->getOpsPerSecond(), 2)
220+
<< PrintColumn(x->getCallsPerSecond(), 2)
221221
<< "\n";
222222

223223
celero::console::SetConsoleColor(celero::console::ConsoleColor_Default);

src/Result.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ double Result::getUsPerCall() const
126126
return static_cast<double>(this->pimpl->stats.getMin()) / static_cast<double>(this->pimpl->problemSpaceIterations);
127127
}
128128

129-
double Result::getOpsPerSecond() const
129+
double Result::getCallsPerSecond() const
130130
{
131131
return 1.0 / (this->getUsPerCall() * 1.0e-6);
132132
}

src/ResultTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void ResultTable::add(std::shared_ptr<Result> x)
101101

102102
this->pimpl->ofs << x->getBaselineMeasurement() << ","
103103
<< x->getUsPerCall() << ","
104-
<< x->getOpsPerSecond() << ","
104+
<< x->getCallsPerSecond() << ","
105105
<< x->getStatistics()->getMin() << ","
106106
<< x->getStatistics()->getMean() << ","
107107
<< x->getStatistics()->getMax() << ","

src/TestFixture.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ uint64_t TestFixture::run(const uint64_t, const uint64_t iterations, int64_t exp
5656
// Set up the testing fixture.
5757
this->setUp(experimentValue);
5858

59-
// Run the test body for each operation.
60-
auto operation = iterations;
59+
// Run the test body for each iterations.
60+
auto iterationCounter = iterations;
6161

6262
// Get the starting time.
6363
const auto startTime = celero::timer::GetSystemTime();
6464

6565
this->onExperimentStart(experimentValue);
6666

67-
while(operation--)
67+
// Count down to zero
68+
while(iterationCounter--)
6869
{
6970
this->UserBenchmark();
7071
}

src/ThreadTestFixture.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ ThreadTestFixture::~ThreadTestFixture()
4646
{
4747
}
4848

49-
void ThreadTestFixture::startThreads(uint64_t threads, uint64_t calls)
49+
void ThreadTestFixture::startThreads(uint64_t threads, uint64_t iterations)
5050
{
51-
const uint64_t callsPerThread = calls / threads;
51+
const uint64_t iterationsPerThread = iterations / threads;
5252

5353
for(uint64_t i = 0; i < threads; ++i)
5454
{
@@ -57,12 +57,12 @@ void ThreadTestFixture::startThreads(uint64_t threads, uint64_t calls)
5757
this->pimpl->futures.push_back(
5858
//std::async(std::launch::deferred,
5959
std::async(std::launch::async,
60-
[this, i, callsPerThread]()
60+
[this, i, iterationsPerThread]()
6161
{
6262
this->pimpl->currentThreadId = i + 1;
63-
for(auto operation = size_t(0); operation < callsPerThread;)
63+
for(auto threadIterationCounter = size_t(0); threadIterationCounter < iterationsPerThread;)
6464
{
65-
this->pimpl->currentCallId = ++operation;
65+
this->pimpl->currentCallId = ++threadIterationCounter;
6666
this->UserBenchmark();
6767
}
6868
}));

test/celero/Utilities.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
TEST(celero_utilities, UsPerSec)
2323
{
2424
EXPECT_EQ(1000000, celero::UsPerSec);
25-
}
25+
}

0 commit comments

Comments
 (0)