folly::FunctionScheduler: Adding support for uniform interval distribution
[folly.git] / folly / Benchmark.h
index dd11a006915b571489ed49fa208a8eb6eb5fae6e..c25ca2800f2907b62da7250553036b9881bb2c8c 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef FOLLY_BENCHMARK_H_
 #define FOLLY_BENCHMARK_H_
 
+#include <folly/ScopeGuard.h>
 #include <folly/Portability.h>
 #include <folly/Preprocessor.h> // for FB_ANONYMOUS_VARIABLE
 #include <cassert>
@@ -26,6 +27,7 @@
 #include <glog/logging.h>
 #include <gflags/gflags.h>
 #include <limits>
+#include <type_traits>
 
 DECLARE_bool(benchmark);
 
@@ -149,6 +151,13 @@ struct BenchmarkSuspender {
     CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &start));
   }
 
+  template <class F>
+  auto dismissing(F f) -> typename std::result_of<F()>::type {
+    SCOPE_EXIT { rehire(); };
+    dismiss();
+    return f();
+  }
+
   /**
    * This is for use inside of if-conditions, used in BENCHMARK macros.
    * If-conditions bypass the explicit on operator bool.
@@ -248,11 +257,19 @@ void doNotOptimizeAway(T&& datum) {
 
 #pragma optimize("", on)
 
+#elif defined(__clang__)
+
+template <class T>
+__attribute__((__optnone__)) void doNotOptimizeAway(T&& datum) {
+}
+
 #else
+
 template <class T>
 void doNotOptimizeAway(T&& datum) {
   asm volatile("" : "+r" (datum));
 }
+
 #endif
 
 } // namespace folly