1
0
mirror of https://github.com/google/benchmark.git synced 2025-04-29 06:20:32 +08:00

add functions that prevent optimization

This commit is contained in:
Eric Fiselier 2015-03-27 04:37:08 -04:00
parent 8b0b73f06c
commit 4567e70d38
2 changed files with 17 additions and 0 deletions
include/benchmark
src

View File

@ -174,8 +174,23 @@ struct EnableIfString<T, typename Voider<typename T::basic_string>::type> {
typedef int type;
};
void UseCharPointer(char const volatile*);
} // end namespace internal
#if defined(__GNUC__)
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
asm volatile("" : "+r" (value));
}
#else
template <class Tp>
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
}
#endif
// State is passed to a running Benchmark and contains state for the
// benchmark to use.
class State {

View File

@ -84,6 +84,8 @@ namespace benchmark {
namespace internal {
void UseCharPointer(char const volatile*) {}
// NOTE: This is a dummy "mutex" type used to denote the actual mutex
// returned by GetBenchmarkLock(). This is only used to placate the thread
// safety warnings by giving the return of GetBenchmarkLock() a name.