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:
parent
8b0b73f06c
commit
4567e70d38
@ -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 {
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user