aboutsummaryrefslogtreecommitdiff
path: root/include/benchmark
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2015-03-06 12:35:00 -0500
committerEric Fiselier <eric@efcs.ca>2015-03-06 12:35:00 -0500
commit5b41e128b359900264464c480dfd4f107625f3c9 (patch)
tree9061e810e559445b3d918ebacf512ad660beeeb5 /include/benchmark
parentc5a362b4d3d7f73c643ef485105e6e3d274da78a (diff)
downloadgoogle-benchmark-5b41e128b359900264464c480dfd4f107625f3c9.tar.gz
Step one towards merging timer changes.
This patch cleans up our use of generic macros and also merges changes in the build system. It adds options -DBENCHMARK_ENABLE_TESTING and -DBENCHMARK_ENABLE_SHARED.
Diffstat (limited to 'include/benchmark')
-rw-r--r--include/benchmark/benchmark.h10
-rw-r--r--include/benchmark/macros.h79
2 files changed, 41 insertions, 48 deletions
diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h
index 58c9c15..2532454 100644
--- a/include/benchmark/benchmark.h
+++ b/include/benchmark/benchmark.h
@@ -295,7 +295,7 @@ class State {
std::unique_ptr<ThreadStats> stats_;
friend class internal::Benchmark;
- DISALLOW_COPY_AND_ASSIGN(State)
+ BENCHMARK_DISALLOW_COPY_AND_ASSIGN(State);
};
// Interface for custom benchmark result printers.
@@ -479,7 +479,7 @@ class Benchmark {
friend struct ::benchmark::internal::Benchmark::Instance;
friend void ::benchmark::internal::RunMatchingBenchmarks(
const std::string&, const BenchmarkReporter*);
- DISALLOW_COPY_AND_ASSIGN(Benchmark)
+ BENCHMARK_DISALLOW_COPY_AND_ASSIGN(Benchmark);
};
// ------------------------------------------------------
@@ -510,7 +510,7 @@ class ConsoleReporter : public BenchmarkReporter {
#define BENCHMARK(n) \
static ::benchmark::internal::Benchmark* BENCHMARK_CONCAT( \
- __benchmark_, n, __LINE__) ATTRIBUTE_UNUSED = \
+ __benchmark_, n, __LINE__) BENCHMARK_UNUSED = \
(new ::benchmark::internal::Benchmark(#n, n))
// Old-style macros
@@ -530,12 +530,12 @@ class ConsoleReporter : public BenchmarkReporter {
// will register BM_Foo<1> as a benchmark.
#define BENCHMARK_TEMPLATE(n, a) \
static ::benchmark::internal::Benchmark* BENCHMARK_CONCAT( \
- __benchmark_, n, __LINE__) ATTRIBUTE_UNUSED = \
+ __benchmark_, n, __LINE__) BENCHMARK_UNUSED = \
(new ::benchmark::internal::Benchmark(#n "<" #a ">", n<a>))
#define BENCHMARK_TEMPLATE2(n, a, b) \
static ::benchmark::internal::Benchmark* BENCHMARK_CONCAT( \
- __benchmark_, n, __LINE__) ATTRIBUTE_UNUSED = \
+ __benchmark_, n, __LINE__) BENCHMARK_UNUSED = \
(new ::benchmark::internal::Benchmark(#n "<" #a "," #b ">", n<a, b>))
#endif // BENCHMARK_BENCHMARK_H_
diff --git a/include/benchmark/macros.h b/include/benchmark/macros.h
index b842bcc..5e75ed3 100644
--- a/include/benchmark/macros.h
+++ b/include/benchmark/macros.h
@@ -1,51 +1,44 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
#ifndef BENCHMARK_MACROS_H_
#define BENCHMARK_MACROS_H_
-#include <assert.h>
-#include <stddef.h>
-
-#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
- TypeName(const TypeName&); \
- void operator=(const TypeName&);
-
-// The arraysize(arr) macro returns the # of elements in an array arr.
-// The expression is a compile-time constant, and therefore can be
-// used in defining new arrays, for example. If you use arraysize on
-// a pointer by mistake, you will get a compile-time error.
-//
-// One caveat is that, for C++03, arraysize() doesn't accept any array of
-// an anonymous type or a type defined inside a function. In these rare
-// cases, you have to use the unsafe ARRAYSIZE() macro below. This is
-// due to a limitation in C++03's template system. The limitation has
-// been removed in C++11.
-
-// This template function declaration is used in defining arraysize.
-// Note that the function doesn't need an implementation, as we only
-// use its type.
-template <typename T, size_t N>
-char (&ArraySizeHelper(T (&array)[N]))[N];
-
-// That gcc wants both of these prototypes seems mysterious. VC, for
-// its part, can't decide which to use (another mystery). Matching of
-// template overloads: the final frontier.
-#ifndef COMPILER_MSVC
-template <typename T, size_t N>
-char (&ArraySizeHelper(const T (&array)[N]))[N];
+#if __cplusplus < 201103L
+# define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&); \
+ TypeName& operator=(const TypeName&)
+#else
+# define BENCHMARK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName&) = delete; \
+ TypeName& operator=(const TypeName&) = delete
#endif
-#define arraysize(array) (sizeof(ArraySizeHelper(array)))
-
-//
-// Prevent the compiler from complaining about or optimizing away variables
-// that appear unused.
-#define ATTRIBUTE_UNUSED __attribute__((unused))
+#if defined(__GNUC__)
+# define BENCHMARK_UNUSED __attribute__((unused))
+# define BENCHMARK_ALWAYS_INLINE __attribute__((always_inline))
+#elif defined(_MSC_VER) && !defined(__clang__)
+# define BENCHMARK_UNUSED
+# define BENCHMARK_ALWAYS_INLINE __forceinline
+#else
+# define BENCHMARK_UNUSED
+# define BENCHMARK_ALWAYS_INLINE
+#endif
-//
-// For functions we want to force inline or not inline.
-// Introduced in gcc 3.1.
-#define ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
-#define HAVE_ATTRIBUTE_ALWAYS_INLINE 1
-#define ATTRIBUTE_NOINLINE __attribute__((noinline))
-#define HAVE_ATTRIBUTE_NOINLINE 1
+#if defined(__GNUC__)
+# define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y)
+#else
+# define BENCHMARK_BUILTIN_EXPECT(x, y) x
+#endif
#endif // BENCHMARK_MACROS_H_