mirror of
https://github.com/google/benchmark.git
synced 2025-02-07 09:40:17 +08:00
Merge pull request #63 from google/62.CHECK
Remove CHECK_* from public API.
This commit is contained in:
commit
66f0b5d0ed
@ -35,17 +35,6 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
|
|||||||
|
|
||||||
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
|
||||||
|
|
||||||
#define CHECK(b) \
|
|
||||||
do { \
|
|
||||||
if (!(b)) assert(false); \
|
|
||||||
} while (0)
|
|
||||||
#define CHECK_EQ(a, b) CHECK((a) == (b))
|
|
||||||
#define CHECK_NE(a, b) CHECK((a) != (b))
|
|
||||||
#define CHECK_GE(a, b) CHECK((a) >= (b))
|
|
||||||
#define CHECK_LE(a, b) CHECK((a) <= (b))
|
|
||||||
#define CHECK_GT(a, b) CHECK((a) > (b))
|
|
||||||
#define CHECK_LT(a, b) CHECK((a) < (b))
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prevent the compiler from complaining about or optimizing away variables
|
// Prevent the compiler from complaining about or optimizing away variables
|
||||||
// that appear unused.
|
// that appear unused.
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "benchmark/benchmark.h"
|
#include "benchmark/benchmark.h"
|
||||||
#include "benchmark/macros.h"
|
#include "check.h"
|
||||||
#include "colorprint.h"
|
#include "colorprint.h"
|
||||||
#include "commandlineflags.h"
|
#include "commandlineflags.h"
|
||||||
#include "re.h"
|
#include "re.h"
|
||||||
|
17
src/check.h
Normal file
17
src/check.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef CHECK_H_
|
||||||
|
#define CHECK_H_
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#define CHECK(b) \
|
||||||
|
do { \
|
||||||
|
if (!(b)) assert(false); \
|
||||||
|
} while (0)
|
||||||
|
#define CHECK_EQ(a, b) CHECK((a) == (b))
|
||||||
|
#define CHECK_NE(a, b) CHECK((a) != (b))
|
||||||
|
#define CHECK_GE(a, b) CHECK((a) >= (b))
|
||||||
|
#define CHECK_LE(a, b) CHECK((a) <= (b))
|
||||||
|
#define CHECK_GT(a, b) CHECK((a) > (b))
|
||||||
|
#define CHECK_LT(a, b) CHECK((a) < (b))
|
||||||
|
|
||||||
|
#endif // CHECK_H_
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <benchmark/macros.h>
|
#include "check.h"
|
||||||
#include "re.h"
|
#include "re.h"
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "benchmark/macros.h"
|
#include "check.h"
|
||||||
#include "cycleclock.h"
|
#include "cycleclock.h"
|
||||||
#include "sleep.h"
|
#include "sleep.h"
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "benchmark/macros.h"
|
#include "check.h"
|
||||||
#include "cycleclock.h"
|
#include "cycleclock.h"
|
||||||
#include "sysinfo.h"
|
#include "sysinfo.h"
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ find_package(Threads REQUIRED)
|
|||||||
# Demonstration executable
|
# Demonstration executable
|
||||||
add_executable(benchmark_test benchmark_test.cc)
|
add_executable(benchmark_test benchmark_test.cc)
|
||||||
target_link_libraries(benchmark_test benchmark ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(benchmark_test benchmark ${CMAKE_THREAD_LIBS_INIT})
|
||||||
add_dependencies(benchmark_test googletest)
|
|
||||||
add_test(benchmark benchmark_test 50)
|
add_test(benchmark benchmark_test 50)
|
||||||
add_test(benchmark_filter_simple benchmark_test --benchmark_filter=Calculate 16)
|
add_test(benchmark_filter_simple benchmark_test --benchmark_filter=Calculate 16)
|
||||||
add_test(benchmark_filter_prefix benchmark_test --benchmark_filter=*Calculate 0)
|
add_test(benchmark_filter_prefix benchmark_test --benchmark_filter=*Calculate 0)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "benchmark/benchmark.h"
|
#include "benchmark/benchmark.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -109,7 +110,7 @@ static void BM_StringCompare(benchmark::State& state) {
|
|||||||
while (state.KeepRunning())
|
while (state.KeepRunning())
|
||||||
r |= s1.compare(s2);
|
r |= s1.compare(s2);
|
||||||
// Prevent compiler optimizations
|
// Prevent compiler optimizations
|
||||||
CHECK(r != std::numeric_limits<int>::max());
|
assert(r != std::numeric_limits<int>::max());
|
||||||
}
|
}
|
||||||
BENCHMARK(BM_StringCompare)->Range(1, 1<<20);
|
BENCHMARK(BM_StringCompare)->Range(1, 1<<20);
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ static void BM_LongTest(benchmark::State& state) {
|
|||||||
while (state.KeepRunning())
|
while (state.KeepRunning())
|
||||||
for (int i = 0; i < state.range_x(); ++i)
|
for (int i = 0; i < state.range_x(); ++i)
|
||||||
tracker += i;
|
tracker += i;
|
||||||
CHECK(tracker != 0.0);
|
assert(tracker != 0.0);
|
||||||
}
|
}
|
||||||
BENCHMARK(BM_LongTest)->Range(1<<16,1<<28);
|
BENCHMARK(BM_LongTest)->Range(1<<16,1<<28);
|
||||||
|
|
||||||
@ -168,8 +169,8 @@ class TestReporter : public benchmark::internal::ConsoleReporter {
|
|||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
benchmark::Initialize(&argc, argv);
|
benchmark::Initialize(&argc, argv);
|
||||||
|
|
||||||
CHECK(Factorial(8) == 40320);
|
assert(Factorial(8) == 40320);
|
||||||
CHECK(CalculatePi(1) == 0.0);
|
assert(CalculatePi(1) == 0.0);
|
||||||
|
|
||||||
TestReporter test_reporter;
|
TestReporter test_reporter;
|
||||||
benchmark::RunSpecifiedBenchmarks(&test_reporter);
|
benchmark::RunSpecifiedBenchmarks(&test_reporter);
|
||||||
|
Loading…
Reference in New Issue
Block a user