/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#ifndef FOLLY_BENCHMARK_H_
#define FOLLY_BENCHMARK_H_
+#include "folly/Portability.h"
#include "folly/Preprocessor.h" // for FB_ANONYMOUS_VARIABLE
#include <cassert>
#include <ctime>
DECLARE_bool(benchmark);
-
namespace folly {
/**
== 2
>::type
addBenchmark(const char* file, const char* name, Lambda&& lambda) {
- auto execute = [=](unsigned int times) {
+ auto execute = [=](unsigned int times) -> uint64_t {
BenchmarkSuspender::nsSpent = 0;
timespec start, end;
// CORE MEASUREMENT STARTS
- CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &start));
+ auto const r1 = clock_gettime(detail::DEFAULT_CLOCK_ID, &start);
lambda(times);
- CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &end));
+ auto const r2 = clock_gettime(detail::DEFAULT_CLOCK_ID, &end);
// CORE MEASUREMENT ENDS
+ CHECK_EQ(0, r1);
+ CHECK_EQ(0, r2);
+
return detail::timespecDiff(end, start) - BenchmarkSuspender::nsSpent;
};