2
0
mirror of https://github.com/boostorg/compute.git synced 2026-01-28 19:12:15 +00:00
Files
compute/perf/perf.hpp
Kyle Lutz ec11d8cdc4 Add third-party perf tests
This adds third-party performance tests to use in comparing
Boost.Compute with other parallel/GPGPU frameworks like Intel's
TBB and NVIDIA's Thrust along with the C++ STL.

Also refactors the timing and profiling infrastructure and adds
a simple perf.py driver script for running performance tests.
2014-02-02 13:12:17 -08:00

99 lines
2.1 KiB
C++

//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://kylelutz.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef PERF_HPP
#define PERF_HPP
// this header contains general purpose functions and variables used by
// the boost.compute performance benchmarks.
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <boost/lexical_cast.hpp>
#include <boost/timer/timer.hpp>
static size_t PERF_N = 1024;
static size_t PERF_TRIALS = 1;
// parses command line arguments and sets the corresponding perf variables
inline void perf_parse_args(int argc, char *argv[])
{
if(argc >= 2){
PERF_N = boost::lexical_cast<size_t>(argv[1]);
}
// TODO: make this configurable from the command line
PERF_TRIALS = 3;
}
// generates a vector of random numbers
template<class T>
std::vector<T> generate_random_vector(const size_t size)
{
std::vector<T> vector(size);
std::generate(vector.begin(), vector.end(), rand);
return vector;
}
// a simple timer wrapper which records multiple time entries
class perf_timer
{
public:
typedef boost::timer::nanosecond_type nanosecond_type;
perf_timer()
{
timer.stop();
}
void start()
{
timer.start();
}
void stop()
{
timer.stop();
times.push_back(timer.elapsed().wall);
}
size_t trials() const
{
return times.size();
}
void clear()
{
times.clear();
}
nanosecond_type last_time() const
{
return times.back();
}
nanosecond_type min_time() const
{
return *std::min_element(times.begin(), times.end());
}
nanosecond_type max_time() const
{
return *std::max_element(times.begin(), times.end());
}
boost::timer::cpu_timer timer;
std::vector<boost::timer::nanosecond_type> times;
};
#endif // PERF_HPP