libmoost
/home/mhx/git/github/libmoost/include/moost/utils/benchmark.hpp File Reference
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "foreach.hpp"
#include "histogram.hpp"
Include dependency graph for benchmark.hpp:

Go to the source code of this file.

Classes

class  moost::utils::benchmark
class  moost::utils::benchmark::timer

Namespaces

namespace  moost
 

Creates a unique temporary directory; removed on scope exit.


namespace  moost::utils

Detailed Description

Copyright © 2008-2013 Last.fm Limited

This file is part of libmoost.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

An easy to use benchmarking statistics class. This isn't yet very sophisticated, but quite capable of producing a nice benchmark statistics for (multithreaded) services with very little code.

Usually, you just need to create a benchmark object

moost::utils::benchmark bm("harold", num_threads);

and then pass a reference to this object to each thread running requests against a service. Within each thread, you can then create a timer object for each request:

If the timer object goes out of scope, it will automatically stop the timer and add the elapsed time to the set of times for the default result specified in the constructor (unless explicitly provided, this will be "error"). You can explicity stop the timer with a different result by calling the stop() method on the timer object. The default result when calling stop() explicitly is "success". You're free to use more results that those two.

After all threads have been joined, simply call the output() method of the benchmark object:

bm.output(std::cout);

This will provide you with histograms for each result type as well as a combined histogram and statistical analysis of the distribution of request times.

Definition in file benchmark.hpp.