From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/compute/perf/perf.hpp | 109 +++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/boost/libs/compute/perf/perf.hpp (limited to 'src/boost/libs/compute/perf/perf.hpp') diff --git a/src/boost/libs/compute/perf/perf.hpp b/src/boost/libs/compute/perf/perf.hpp new file mode 100644 index 00000000..cce0328c --- /dev/null +++ b/src/boost/libs/compute/perf/perf.hpp @@ -0,0 +1,109 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2013-2014 Kyle Lutz +// +// 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://boostorg.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 +#include +#include + +#include +#include + +static size_t PERF_N = 1024; +static size_t PERF_TRIALS = 3; + +// 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(argv[1]); + } + + if(argc >= 3){ + PERF_TRIALS = boost::lexical_cast(argv[2]); + } +} + +// generates a vector of random numbers +template +std::vector generate_random_vector(const size_t size) +{ + std::vector 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 times; +}; + +// returns the rate (in MB/s) for processing 'count' items of type 'T' +// in 'time' nanoseconds +template +double perf_rate(const size_t count, perf_timer::nanosecond_type time) +{ + const size_t byte_count = count * sizeof(T); + + return (double(byte_count) / 1024 / 1024) / (time / 1e9); +} + +#endif // PERF_HPP -- cgit v1.2.3