Adding support for signed integers
[folly.git] / folly / Benchmark.h
index 444ad81d216a87325911d1d66121f2c5ce7c17d9..19806028a96242a2cd45cf288fdadaabbacb9633 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -17,6 +17,7 @@
 #ifndef FOLLY_BENCHMARK_H_
 #define FOLLY_BENCHMARK_H_
 
+#include "folly/Portability.h"
 #include "folly/Preprocessor.h" // for FB_ANONYMOUS_VARIABLE
 #include <cassert>
 #include <ctime>
@@ -28,7 +29,6 @@
 
 DECLARE_bool(benchmark);
 
-
 namespace folly {
 
 /**
@@ -185,16 +185,19 @@ typename std::enable_if<
   == 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;
   };