55 template<
typename T,
typename ...Ts>
59 if (
sizeof...(Ts) > 0)
134 template<
typename FUNC,
typename... ARGS>
140 std::cout << (*this) << std::endl;
146 double avg()
const {
return m_avg; }
147 double stddev()
const {
return m_stddev; }
148 double range()
const {
return m_range; }
149 double median()
const {
return m_median; }
156 m_user_iterations =
val;
167 size_t trials()
const {
return m_trials; }
182 size_t work()
const {
return m_work; }
191 m_exclude_outliers = e;
232 size_t m_iterations = 0;
233 size_t m_user_iterations = 0;
234 size_t m_trials = 10;
237 std::vector<double> m_times;
242 int m_exclude_outliers = 1;
245 Unit m_units = Unit::autounit;
247 template<
typename FUNC,
typename... ARGS>
248 double run(FUNC
func, ARGS&&...
args)
250 if (m_user_iterations)
251 m_iterations = m_user_iterations;
253 m_iterations = determine_iterations(func,
args...);
254 m_times.resize(m_trials);
256 double overhead = iteration_overhead() * iterations();
257 for (
auto&
t : m_times)
258 t =
std::max(0.0, do_trial(m_iterations, func,
args...) - overhead);
263 template<
typename FUNC,
typename... ARGS>
264 size_t determine_iterations(FUNC func, ARGS&&...
args)
267 const double target_time = 0.01;
270 double t = do_trial (i, func,
args...);
272 if (t > target_time * 1.5 && i > 2)
274 if (t > target_time * 0.75 || i > (
size_t(1) << 30))
276 if (t < target_time / 16)
283 template<
typename FUNC,
typename... ARGS>
284 double do_trial(
size_t iterations, FUNC func, ARGS&&...
args)
287 while (iterations--) {
294 void compute_stats() { compute_stats(m_times, m_iterations); }
295 void compute_stats(std::vector<double>& times,
size_t iterations);
296 double iteration_overhead();
311 template<
typename FUNC>
315 double mintime = 1.0e30, maxtime = 0.0;
316 while (ntrials-- > 0) {
318 for (
int i = 0; i < nrepeats; ++i) {
330 *
range = maxtime - mintime;
335 template<
typename FUNC>
370 int total_iterations,
int ntrials,
371 cspan<int> threadcounts = {1,2,4,8,12,16,24,32,48,64,128});
378 int maxthreads,
int total_iterations,
int ntrials,
379 cspan<int> threadcounts = {1,2,4,8,12,16,24,32,48,64,128});
395 #if ((OIIO_GNUC_VERSION && NDEBUG) || OIIO_CLANG_VERSION >= 30500 || OIIO_APPLE_CLANG_VERSION >= 70000 || defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)) \
396 && (defined(__x86_64__) || defined(__i386__))
403 #if defined(__clang__)
407 asm volatile(
"" : :
"g"(
val) :
"memory");
409 asm volatile(
"" : :
"i,r,m"(
val) :
"memory");
417 #pragma optimize("", off)
421 _ReadWriteBarrier ();
424 #pragma optimize("", on)
426 #elif __has_attribute(__optnone__)
449 #if ((OIIO_GNUC_VERSION && NDEBUG) || OIIO_CLANG_VERSION >= 30500 || OIIO_APPLE_CLANG_VERSION >= 70000 || defined(__INTEL_COMPILER)) && (defined(__x86_64__) || defined(__i386__))
453 asm volatile (
"" : : :
"memory");
459 _ReadWriteBarrier ();
void OIIO_UTIL_API clobber(void *p)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
Benchmarker & indent(int spaces)
size_t iterations() const
void OIIO_UTIL_API use_char_ptr(char const volatile *)
GLsizei const GLchar *const * string
String-related utilities, all in namespace Strutil.
Benchmarker & verbose(int v)
OIIO_FORCEINLINE void clobber_all_memory()
__attribute__((visibility("default")))
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
int exclude_outliers() const
const std::string & name() const
Benchmarker & units(Unit s)
GLuint const GLchar * name
double time_trial(FUNC func, int ntrials=1, int nrepeats=1, double *range=NULL)
Benchmarker & work(size_t val)
Benchmarker & iterations(size_t val)
Benchmarker & exclude_outliers(int e)
OIIO_NAMESPACE_BEGIN OIIO_FORCEINLINE T const & DoNotOptimize(T const &val)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
**If you just want to fire and args
#define OIIO_NAMESPACE_END
double operator()(string_view name, FUNC func, ARGS &&...args)
Benchmarker & trials(size_t val)
OIIO_UTIL_API std::vector< double > timed_thread_wedge(function_view< void(int)> task, function_view< void()> pretask, function_view< void()> posttask, std::ostream *out, int maxthreads, int total_iterations, int ntrials, cspan< int > threadcounts={1, 2, 4, 8, 12, 16, 24, 32, 48, 64, 128})
#define OIIO_NAMESPACE_BEGIN