Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C++

Celero - A C++ Benchmark Authoring Library

Rate me:
Please Sign up or sign in to vote.
4.84/5 (19 votes)
31 Oct 2013Apache7 min read 47.5K   764   49  
This article discusses how to implement and use a template-based C++ benchmarking library.
#include <celero/Celero.h>

CELERO_MAIN;

// Run an automatic baseline.  
// Celero will help make sure enough samples are taken to get a reasonable measurement
BASELINE(DemoSimple, Baseline, 0, 7100000)
{
	celero::DoNotOptimizeAway(static_cast<float>(sin(3.14159265)));
}

// In reality, all of the "Complex" cases take the same amount of time to run.
// The difference in the results is a product of measurement error.

// Run an automatic test.  
// Celero will help make sure enough samples are taken to get a reasonable measurement
BENCHMARK(DemoSimple, Complex1, 0, 7100000)
{
	celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(rand(), 3.14159265))));
}

// Run a manual test consisting of 1 sample of 7100000 operations per measurement.
// Celero will help make sure enough samples are taken to get a reasonable measurement
BENCHMARK(DemoSimple, Complex2, 1, 7100000)
{
	celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(rand(), 3.14159265))));
}

// Run a manual test consisting of 60 samples of 7100000 operations per measurement.
// Celero will help make sure enough samples are taken to get a reasonable measurement
BENCHMARK(DemoSimple, Complex3, 60, 7100000)
{
	celero::DoNotOptimizeAway(static_cast<float>(sin(fmod(rand(), 3.14159265))));
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Team Leader
United States United States
John Farrier is a professional C++ software engineer that specializes in modeling, simulation, and architecture development.

Specialties:

LVC Modeling & Simulation
Software Engineering, C++11, C++98, C, C#, FORTRAN, Python
Software Performance Optimization
Software Requirements Development
Technical Project and Team Leadership

Comments and Discussions