Commit Graph

275 Commits

Author SHA1 Message Date
Marat Dukhan 7fb3c564e5 Fix compilation on Android with GNU STL (#596)
* Fix compilation on Android with GNU STL

GNU STL in Android NDK lacks string conversion functions from C++11, including std::stoul, std::stoi, and std::stod.
This patch reimplements these functions in benchmark:: namespace using C-style equivalents from C++03.

* Avoid use of log2 which doesn't exist in Android GNU STL

GNU STL in Android NDK lacks log2 function from C99/C++11.
This patch replaces their use in the code with double log(double) function.
2018-06-05 11:36:26 +01:00
BaaMeow 4c2af07889 (clang-)format all the things (#610)
* format all documents according to contributor guidelines and specifications
use clang-format on/off to stop formatting when it makes excessively poor decisions

* format all tests as well, and mark blocks which change too much
2018-06-01 11:14:19 +01:00
Dominic Hamon 16703ff83c
cleaner and slightly larger statistics tests (#604) 2018-05-29 13:13:06 +01:00
Alex Strelnikov e776aa0275 Add benchmark_main target. (#601)
* Add benchmark_main library with support for Bazel.

* fix newline at end of file

* Add CMake support for benchmark_main.

* Mention optionally using benchmark_main in README.
2018-05-25 11:18:58 +01:00
Samuel Panzer ce3fde16cb Return 0 from State::iterations() when not yet started. (#598)
* Return a reasonable value from State::iterations() even before starting a benchmark

* Optimize State::iterations() for started case.
2018-05-24 10:33:19 +01:00
Deniz Evrenci 6d74c0625b split_list is not defined for assembly tests (#595)
* Update AUTHORS and CONTRIBUTORS

* split_list is not defined for assembly tests
2018-05-14 15:02:49 +01:00
Tim Bradgate ed1bac8434 Issue 571: Allow support for negative regex filtering (#576)
* Allow support for negative regex filtering

This patch allows one to apply a negation to the entire regex filter
by appending it with a '-' character, much in the same style as
GoogleTest uses.

* Address issues in PR

* Add unit tests for negative filtering
2018-04-26 10:56:06 +01:00
Dominic Hamon 64e5a13fa0
Ensure 64-bit truncation doesn't happen for complexity_n (#569)
* Ensure 64-bit truncation doesn't happen for complexity results

* One more complexity_n 64-bit fix

* Missed another vector of int

* Piping through the int64_t
2018-04-12 15:40:24 +01:00
Dominic Hamon 9913418d32
Allow AddRange to work with int64_t. (#548)
* Allow AddRange to work with int64_t.

Fixes #516

Also, tweak how we manage per-test build needs, and create a standard
_gtest suffix for googletest to differentiate from non-googletest tests.

I also ran clang-format on the files that I changed (but not the
benchmark include or main src as they have too many clang-format
issues).

* Add benchmark_gtest to cmake

* Set(Items|Bytes)Processed now take int64_t
2018-04-03 23:12:47 +01:00
Dominic Hamon e7eb54b5f8
Fix uninitialized warning (#560) 2018-03-25 20:05:31 +01:00
Eric 7b03df7ff7
Add tests to verify assembler output -- Fix DoNotOptimize. (#530)
* Add tests to verify assembler output -- Fix DoNotOptimize.

For things like `DoNotOptimize`, `ClobberMemory`, and even `KeepRunning()`,
it is important exactly what assembly they generate. However, we currently
have no way to test this. Instead it must be manually validated every
time a change occurs -- including a change in compiler version.

This patch attempts to introduce a way to test the assembled output automatically.
It's mirrors how LLVM verifies compiler output, and it uses LLVM FileCheck to run
the tests in a similar way.

The tests function by generating the assembly for a test in CMake, and then
using FileCheck to verify the // CHECK lines in the source file are found
in the generated assembly.

Currently, the tests only run on 64-bit x86 systems under GCC and Clang,
and when FileCheck is found on the system.

Additionally, this patch tries to improve the code gen from DoNotOptimize.
This should probably be a separate change, but I needed something to test.

* Disable assembly tests on Bazel for now

* Link FIXME to github issue

* Fix Tests on OS X

* fix strip_asm.py to work on both Linux and OS X like targets
2018-03-23 16:10:47 -06:00
Dominic Hamon df60aeb266
Rely on compiler intrinsics to identify regex engine. (#555)
Having the copts set on a per-target level can lead to ODR violations
in some cases. Avoid this by ensuring the regex engine is picked
through compiler intrinsics in the header directly.
2018-03-23 11:45:15 +00:00
Eric Fiselier 68e228944e Fix #538 - gtest.h not found when building with older CMake versions.
Older CMake versions, in particular 2.8, don't seem to correctly handle
interface include directories. This causes failures when building the
tests. Additionally, older CMake versions use a different library install
directory than expected (i.e. they use lib/<target-triple>). This caused
certain tests to fail to link.

This patch fixes both those issues. The first by manually adding the
correct include directory when building the tests. The second by specifying
the library output directory when configuring the GTest build.
2018-03-21 13:27:04 -06:00
jmillikin-stripe a9beffda0b Add support for building with Bazel. (#533)
* Add myself to CONTRIBUTORS under the corp CLA for Stripe, Inc.

* Add support for building with Bazel.

Limitations compared to existing CMake rules:
* Defaults to using C++11 `<regex>`, with an override via Bazel flag
  `--define` of `google_benchmark.have_regex`. The TravisCI config sets
  the regex implementation to `posix` because it uses ancient compilers.
* Debug vs Opt mode can't be set per test. TravisCI runs all the tests
  in debug mode to satisfy `diagnostics_test`, which depends on `CHECK`
  being live.

* Set Bazel workspace name so other repos can refer to it by stable name.

This is recommended by the Bazel style guide to avoid each dependent
workspace defining its own name for the dependency.
2018-03-08 12:48:46 +00:00
Eric 56f52ee228 Print the executable name as part of the context. (#534)
* Print the executable name as part of the context.

A common use case of the library is to run two different
versions of a benchmark to compare them. In my experience
this often means compiling a benchmark twice, renaming
one of the executables, and then running the executables
back-to-back. In this case the name of the executable
is important contextually information.  Unfortunately the
benchmark does not report this information.

This patch adds the executable name to the context reported
by the benchmark.

* attempt to fix tests on Windows

* attempt to fix tests on Windows
2018-02-21 08:43:57 -08:00
Eric Fiselier 858688b845 Ensure std::iterator_traits<StateIterator> instantiates.
Due to ADL lookup performed on the begin and end functions
of `for (auto _ : State)`, std::iterator_traits may get
incidentally instantiated. This patch ensures the library
can tolerate that.
2018-02-21 00:54:19 -07:00
Eric Fiselier dd8dcc8da1 Make output tests more stable on slow machines.
The appveyor bot sometimes fails because the time it
outputs is 6 digits long, but the output test regex expects at most
5 digits. This patch increases the size to 6 digits to placate the
test. This should not *really* affect the correctness of the test.
2018-02-12 19:07:19 -07:00
Samuel Panzer 296ec5693e Support State::KeepRunningBatch(). (#521)
* Support State::KeepRunningBatch().

State::KeepRunning() can take large amounts of time relative to quick
operations (on the order of 1ns, depending on hardware). For such
sensitive operations, it is recommended to run batches of repeated
operations.

This commit simplifies handling of total_iterations_. Rather than
predecrementing such that total_iterations_ == 1 signals that
KeepRunning() should exit, total_iterations_ == 0 now signals the
intention for the benchmark to exit.

* Create better fast path in State::KeepRunningBatch()

* Replace int parameter with size_t to fix signed mismatch warnings

* Ensure benchmark State has been started even on error.

* Simplify KeepRunningBatch()
2018-02-09 21:57:04 -07:00
Eric 7db02be244
Add support for GTest based unit tests. (#485)
* Add support for GTest based unit tests.

As Dominic and I have previously discussed, there is some
need/desire to improve the testing situation in Google Benchmark.

One step to fixing this problem is to make it easier to write
unit tests by adding support for GTest, which is what this patch does.

By default it looks for an installed version of GTest. However the
user can specify -DBENCHMARK_BUILD_EXTERNAL_GTEST=ON to instead
download, build, and use copy of gtest from source. This is
quite useful when Benchmark is being built in non-standard configurations,
such as against libc++ or in 32 bit mode.
2017-12-13 16:26:47 -07:00
Louis Dionne 5b2c08668c Enforce using a semicolon after BENCHMARK_MAIN to remove compiler warnings (#495) 2017-12-03 18:45:07 -07:00
Eric 11dc36822b
Improve CPU Cache info reporting -- Add Windows support. (#486)
* Improve CPU Cache info reporting -- Add Windows support.

This patch does a couple of thing regarding CPU Cache reporting.

First, it adds an implementation on Windows. Second it fixes
the JSONReporter to correctly (and actually) output the CPU
configuration information.

And finally, third, it detects and reports the number of
physical CPU's that share the same cache.
2017-11-26 13:33:01 -07:00
Leo Koppel fa341e51cb Improve BM_SetInsert example (#465)
* Fix BM_SetInsert example

Move declaration of `std::set<int> data` outside the timing loop, so that the
destructor is not timed.

* Speed up BM_SetInsert test

Since the time taken to ConstructRandomSet() is so large compared to the time
to insert one element, but only the latter is used to determine number of
iterations, this benchmark now takes an extremely long time to run in
benchmark_test.

Speed it up two ways:
  - Increase the Ranges() parameters
  - Cache ConstructRandomSet() result (it's not random anyway), and do only
    O(N) copy every iteration

* Fix same issue in BM_MapLookup test

* Make BM_SetInsert test consistent with README

- Use the same Ranges everywhere, but increase the 2nd range
- Change order of Args() calls in README to more closely match the result of Ranges
- Don't cache ConstructRandomSet, since it doesn't make sense in README
- Get a smaller optimization inside it, by givint a hint to insert()
2017-10-31 11:00:39 -07:00
Eric 25acf220a4 Refactor most usages of KeepRunning to use the perfered ranged-for. (#459)
Recently the library added a new ranged-for variant of the KeepRunning
loop that is much faster. For this reason it should be preferred in all
new code.

Because a library, its documentation, and its tests should all embody
the best practices of using the library, this patch changes all but a
few usages of KeepRunning() into for (auto _ : state).

The remaining usages in the tests and documentation persist only
to document and test behavior that is different between the two formulations.

Also note that because the range-for loop requires C++11, the KeepRunning
variant has not been deprecated at this time.
2017-10-17 12:17:02 -06:00
Eric Fiselier 22fd1a556e Fix and document SkipWithError(...) using ranged-for loop. 2017-10-17 10:24:13 -06:00
Eric 0526755944 Add C++11 Ranged For loop alternative to KeepRunning (#454)
* Add C++11 Ranged For loop alternative to KeepRunning

As pointed out by @astrelni and @dominichamon, the KeepRunning
loop requires a bunch of memory loads and stores every iterations,
which affects the measurements.

The main reason for these additional loads and stores is that the
State object is passed in by reference, making its contents externally
visible memory, and the compiler doesn't know it hasn't been changed
by non-visible code.

It's also possible the large size of the State struct is hindering
optimizations.

This patch allows the `State` object to be iterated over using
a range-based for loop. Example:

void BM_Foo(benchmark::State& state) {
	for (auto _ : state) {
		[...]
	}
}

This formulation is much more efficient, because the variable counting
the loop index is stored in the iterator produced by `State::begin()`,
which itself is stored in function-local memory and therefore not accessible
by code outside of the function. Therefore the compiler knows the iterator
hasn't been changed every iteration.

This initial patch and idea was from Alex Strelnikov.

* Fix null pointer initialization in C++03
2017-10-10 08:56:42 -07:00
Anton Lashkov 819adb4cd1 Add macros for create benchmark with templated fixture (#451)
* Add macros for create benchmark with templated fixture

* Add info about templated fixtures to README.md

* Add tests for templated fixtures
2017-10-09 21:10:37 +02:00
Eric 6d8339dd97 Fix #444 - Use BENCHMARK_HAS_CXX11 over __cplusplus. (#446)
* Fix #444 - Use BENCHMARK_HAS_CXX11 over __cplusplus.

MSVC incorrectly defines __cplusplus to report C++03, despite the compiler
actually providing C++11 or greater. Therefore we have to detect C++11 differently
for MSVC. This patch uses `_MSVC_LANG` which has been defined since
Visual Studio 2015 Update 3; which should be sufficient for detecting C++11.

Secondly this patch changes over most usages of __cplusplus >= 201103L to
check BENCHMARK_HAS_CXX11 instead.

* remove redunant comment
2017-09-14 15:50:33 -06:00
Roman Lebedev a271c36af9 Drop Stat1, refactor statistics to be user-providable, add median. (#428)
* Drop Stat1, refactor statistics to be user-providable, add median.

My main goal was to add median statistic. Since Stat1
calculated the stats incrementally, and did not store
the values themselves, it is was not possible. Thus,
i have replaced Stat1 with simple std::vector<double>,
containing all the values.

Then, i have refactored current mean/stdev to be a
function that is provided with values vector, and
returns the statistic. While there, it seemed to make
sense to deduplicate the code by storing all the
statistics functions in a map, and then simply iterate
over it. And the interface to add new statistics is
intentionally exposed, so they may be added easily.

The notable change is that Iterations are no longer
displayed as 0 for stdev. Is could be changed, but
i'm not sure how to nicely fit that into the API.

Similarly, this dance about sometimes (for some fields,
for some statistics) dividing by run.iterations, and
then multiplying the calculated stastic back is also
dropped, and if you do the math, i fail to see why
it was needed there in the first place.

Since that was the only use of stat.h, it is removed.

* complexity.h: attempt to fix MSVC build

* Update README.md

* Store statistics to compute in a vector, ensures ordering.

* Add a bit more tests for repetitions.

* Partially address review notes.

* Fix gcc build: drop extra ';'

clang, why didn't you warn me?

* Address review comments.

* double() -> 0.0
* early return
2017-08-23 16:44:29 -07:00
Roman Lebedev 3347a20e0e reporter_output_test: json: iterations is int, not float (#431)
May be relevant for flakiness of win builds

Noted by @KindDragon
2017-07-31 19:04:02 -06:00
Eric Fiselier abafced990 Suppress -Wodr on C++03 tests when LTO is enabled.
The benchmark library is compiled as C++11, but certain
tests are compiled as C++03. When -flto is enabled GCC 5.4
and above will diagnose an ODR violation in libstdc++'s <map>.

This ODR violation, although real, should likely be benign. For
this reason it seems sensible to simply suppress -Wodr when building
the C++03 test.

This patch fixes #420 and supersede's PR #424.
2017-07-30 18:44:04 -06:00
Roman Lebedev b9be142d1e Json reporter: don't cast floating-point to int; adjust tooling (#426)
* Json reporter: passthrough fp, don't cast it to int; adjust tooling

Json output format is generally meant for further processing
using some automated tools. Thus, it makes sense not to
intentionally limit the precision of the values contained
in the report.

As it can be seen, FormatKV() for doubles, used %.2f format,
which was meant to preserve at least some of the precision.
However, before that function is ever called, the doubles
were already cast to the integer via RoundDouble()...

This is also the case for console reporter, where it makes
sense because the screen space is limited, and this reporter,
however the CSV reporter does output some( decimal digits.

Thus i can only conclude that the loss of the precision
was not really considered, so i have decided to adjust the
code of the json reporter to output the full fp precision.

There can be several reasons why that is the right thing
to do, the bigger the time_unit used, the greater the
precision loss, so i'd say any sort of further processing
(like e.g. tools/compare_bench.py does) is best done
on the values with most precision.

Also, that cast skewed the data away from zero, which
i think may or may not result in false- positives/negatives
in the output of tools/compare_bench.py

* Json reporter: FormatKV(double): address review note

* tools/gbench/report.py: skip benchmarks with different time units

While it may be useful to teach it to operate on the
measurements with different time units, which is now
possible since floats are stored, and not the integers,
but for now at least doing such a sanity-checking
is better than providing misinformation.
2017-07-24 16:13:55 -07:00
Eric 9d4b719dae Make Benchmark a single header library (but not header-only) (#407)
* Make Benchmark a single header library (but not header-only)

This patch refactors benchmark into a single header, to allow
for slightly easier usage.

The initial reason for the header split was to keep C++ library
components from being included by benchmark_api.h, making that
part of the library STL agnostic. However this has since changed
and there seems to be little reason to separate the reporters from
the rest of the library.

* Fix internal_macros.h

* Remove more references to macros.h
2017-07-04 16:31:47 -06:00
Eric b8a2206fb2 Add ClearRegisteredBenchmark() function. (#402)
* Add ClearRegisteredBenchmark() function.

Since benchmarks can be registered at runtime using the RegisterBenchmark(...)
functions, it makes sense to have a ClearRegisteredBenchmarks() function too,
that can be used at runtime to clear the currently registered benchmark and
re-register an entirely new set.

This allows users to run a set of registered benchmarks, get the output using
a custom reporter, and then clear and re-register new benchmarks based on the
previous results.

This fixes issue #400, at least partially.

* Remove unused change
2017-06-14 09:16:53 -07:00
Eric 93bfabc8b8 Fix #342: DoNotOptimize causes compile errors on older GCC versions. (#398)
* Fix #342: DoNotOptimize causes compile errors on older GCC versions.

DoNotOptimize uses inline assembly contraints to tell
the compiler what the type of the input variable. The 'g'
operand allows the input to be any register, memory, or
immediate integer operand. However this constraint seems
to be too weak on older GCC versions, and certain inputs
will cause compile errors.

This patch changes the constraint to 'X', which is documented
as "any operand whatsoever is allowed". This appears to fix
the issues with older GCC versions.

However Clang doesn't seem to like "X", and will attempt
to put the input into a register even when it can't/shouldn't;
causing a compile error. However using "g" seems to work like
"X" with GCC, so for this reason Clang still uses "g".

* Try alternative formulation to placate GCC
2017-06-02 15:47:23 -07:00
Joao Paulo Magalhaes ec6f03579e Trying again to fix error caused by -Wunused-function.
This thing with the pragma ignore was getting out of hand: now
MinGW (and probably GCC) was erroring too. So I chose to move
the definition of IsZero() out of the anonymous namespace into
benchmark.cc.
2017-05-03 00:05:15 +01:00
Joao Paulo Magalhaes 1735413188 Fix pragma clang ignore with gcc. 2017-05-02 23:35:46 +01:00
Joao Paulo Magalhaes 160770fd08 Fix dropped-style elses. 2017-05-02 23:30:36 +01:00
Joao Paulo Magalhaes a31088632a Fix (that is, ignore) clang compile error. 2017-05-02 23:25:22 +01:00
Joao Paulo Magalhaes 020bac985b Extend tabular counter tests to different counter sets. 2017-05-02 23:00:45 +01:00
Joao Paulo Magalhaes 2506044902 Add unit test for counter sets. 2017-05-02 22:14:49 +01:00
Joao Paulo Magalhaes cf20dc967f Add test for tabular output of rate counters. 2017-05-02 20:47:41 +01:00
Joao Paulo Magalhaes c69b385c9c Add first unit test for benchmark_tabular_counters. 2017-05-02 20:33:28 +01:00
Joao Paulo Magalhaes 17a012d754 Fix: --benchmark_counters_tabular was not being passed to tests. 2017-05-02 20:31:54 +01:00
Joao Paulo Magalhaes 77b9362b06 Add output_test.h to output_test_helper for VisualStudio editing. 2017-05-01 23:02:52 +01:00
Joao Paulo Magalhaes b57b2cfd77 Improve some comments. 2017-05-01 23:02:35 +01:00
Joao Paulo Magalhaes 64b5f3ff2d Make Results::GetTime() receive an enum. 2017-05-01 23:02:23 +01:00
Joao Paulo Magalhaes 62b1dd9c4a CHECK_BENCHMARK_RESULTS() was too inconspicuous. 2017-05-01 23:02:17 +01:00
Joao Paulo Magalhaes 3443ac2103 Fix brace formatting (Habits die hard!). 2017-05-01 23:02:11 +01:00
Joao Paulo Magalhaes 21600b966f Fix VS warning. 2017-05-01 23:01:57 +01:00
Joao Paulo Magalhaes 47226ccd56 CHECK(): rename EPS to FLOAT for consistency with googletest style. 2017-05-01 23:01:10 +01:00
Joao Paulo Magalhaes 2a2eb44b30 Fix VS2013 quirk. 2017-04-29 22:27:55 +01:00
Joao Paulo Magalhaes cdbcaaf2b6 Fix g++-4.8 compile errors. 2017-04-29 20:47:32 +01:00
Joao Paulo Magalhaes 8f69e4f6ce Remove whitespace. 2017-04-29 20:35:25 +01:00
Joao Paulo Magalhaes c81960a899 Add missing include of stringstream. 2017-04-29 20:31:44 +01:00
Joao Paulo Magalhaes b5effb30f9 Add missing include for providing std::function. 2017-04-29 20:24:26 +01:00
Joao Paulo Magalhaes 55876610f1 Remove unused prototype. 2017-04-29 20:02:19 +01:00
Joao Paulo Magalhaes 180719d0d6 Rename ResultsCheckerEntry to Results. 2017-04-29 20:01:18 +01:00
Joao Paulo Magalhaes f3b82a8eda Adopt standard style. 2017-04-29 19:44:13 +01:00
Joao Paulo Magalhaes 86249c57a5 Result checking: move some function definitions to source file. 2017-04-29 19:40:39 +01:00
Joao Paulo Magalhaes 03b0655d12 Fix expected values of user counters as rates in unit tests. 2017-04-29 19:35:43 +01:00
Joao Paulo Magalhaes 78548f8c6e Add (currently failing) tests for user counters with threads. 2017-04-29 19:26:34 +01:00
Joao Paulo Magalhaes 2814e9d8dc Fix ResultsCheckerEntry::NumThreads() 2017-04-29 19:25:51 +01:00
Joao Paulo Magalhaes 92034a8b84 Make result checkers execute on all regex-matching benchmarks. 2017-04-29 19:02:07 +01:00
Joao Paulo Magalhaes 738fcd9e6a Add log of the benchmark name when checking results. 2017-04-29 18:30:28 +01:00
Joao Paulo Magalhaes 1ce286f632 Avoid compiler-specific pragmas in result check macros.
- Epsilon is now understood as relative to expected value.
- Improve error messages for epsilon checks.
2017-04-29 18:26:30 +01:00
Joao Paulo Magalhaes da69e5de45 User counters: add more tests. 2017-04-28 20:45:30 +01:00
Joao Paulo Magalhaes 8c757a3bb9 Results check: add checks with epsilon. 2017-04-28 20:44:27 +01:00
Joao Paulo Magalhaes 1826feb164 ResultsCheckerEntry: add more getter functions. 2017-04-28 20:43:44 +01:00
Joao Paulo Magalhaes 2a8d0dd1b1 Use const char* instead of std::string in entry name lookup. 2017-04-28 20:42:28 +01:00
Joao Paulo Magalhaes e869e3749a Remove some whitespace. 2017-04-28 15:38:21 +01:00
Joao Paulo Magalhaes 6452883027 Unit testing: add facilities to check benchmark results.
This is needed for examining the values of user counters (needed
for #348). It is also needed for checking the values of standard
benchmark results like items_processed or complexities (for example,
checking the standard deviation is needed for unit testing #357
as discussed in #362).
2017-04-28 15:02:27 +01:00
Joao Paulo Magalhaes 693a43013d User counters: add more unit tests. ...
The tests are still missing a way to check actual validity of
numerical results; this will be done next. As they currently are,
the tests pass, but the problem detected with #378 is still
standing and the results with non-standard counters are wrong.
2017-04-27 22:11:40 +01:00
Joao Paulo Magalhaes 3c2d7f5348 User counter tests: first version. 2017-04-27 19:25:20 +01:00
Joao Paulo Magalhaes b273d9b7d5 Reporter tests: reuse csv header. 2017-04-27 19:24:06 +01:00
Dmitry Trifonov 7a74b74856 fix for android NDK r10e (#375) 2017-04-20 20:07:52 -06:00
Dmitry Trifonov 09b93ccc6a fix android compilation (#372)
* fix android compilation

* checking __GLIBCXX__ and __GLIBCPP__ macro in addition to __ANDROID__

* using vsnprintf instead of std::vsnprintf to compile on Android

* removed __GLIBCPP__ check on Android

* StringPrintF instead of std::to_string for Android
2017-04-18 09:48:07 -06:00
Eric 74b24058ad Add Benchmark::Iterations for explicit iteration count control - Fixes #370 (#373)
* Add Benchmark::Iterations for explicitly specifying the number of iterations to use.

* Document that benchmark::Iterations should not be used to limit benchmark runtimes
2017-04-17 21:29:28 -07:00
Eric Fiselier 7f87c98d36 Enable <cassert> by removing -DNDEBUG when running the tests.
In non-debug builds CMake automatically adds -DNDEBUG, this means
that uses of `assert` in the tests are disabled for non-debug builds.
Obviously we want these tests to run, regardless of configuration.

This patch strips -DNDEBUG during non-debug builds and adds
-UNDEBUG just to be sure.
2017-04-17 20:53:39 -06:00
rolandschulz 9b92ed76a8 Fix ICC compiler warnings (#358)
fixes #354

The build fails with ICC17 because of warnings and Werror. What is the correct solution to fix it?
Should a patch

disable Werror for ICC (or maybe all non known compilers)
disable the false postive warnings for all files. This could be done using:
add_cxx_compiler_flag(-wd2102) #ICC17u2: Many false positives for Wstrict-aliasing
add_cxx_compiler_flag(-wd2259) #ICC17u2: non-pointer conversion from "long" to "int" may lose significant bits (even for explicit static cast, sleep.cc(44))
add_cxx_compiler_flag(-wd654) #ICC17u2: overloaded virtual function "benchmark::Fixture::SetUp" is only partially overridden (because of deprecated overload)
disable warnings at file level or some other granularity
2017-03-27 18:30:54 -06:00
jpmag a9a66c85bb Add user-defined counters. (#262)
* Added user counters, and move use of bytes_processed and items_processed to user counter logic.

Each counter is a string-value pair. The counters were
made available through the State class. Two helper virtual
methods were added to the Fixture class to allow convenient
initialization and termination of the counters: InitState()
and TerminateState(). The reporting of the counters is buggy
and is still a work in progress, to be completed in the next commits.

* fix bad removal of BenchmarkCounters code during the merge

* add myself to AUTHORS/CONTRIBUTORS

* fix printing to std::cout in csv_reporter

* bytes_per_second and items_per_second are now in the UserCounters class

* add user counters to json reporter

* moving bytes_per_second and items_per_second to their old state

* console reporter dealing ok with user counters.

* update unit tests for user counters

* CSVReporter now prints user counters too.

* cleanup user counters

* reverted changes to cmake files which should have gone into later commits

* fixture_test: fix gcc 4.6 compilation

* remove ctor with default argument

see https://github.com/google/benchmark/pull/262#discussion_r72298055

* use (auto-defined) BENCHMARK_HAS_CXX11 instead of BENCHMARK_INITLIST.

https://github.com/google/benchmark/pull/262#discussion_r72298310

* leanify counters API

Discussions:
API complexity: https://github.com/google/benchmark/pull/262#discussion_r72298731
remove std::string dependency (WIP): https://github.com/google/benchmark/pull/262#discussion_r72298142
spacing & alignment: https://github.com/google/benchmark/pull/262#discussion_r72298422

* remove std::string dependency on public API - changed counter name storage to char*

* Counter ctor: use overloads instead of default arguments

discussion:
https://github.com/google/benchmark/pull/262#discussion_r72298055

* Use raw pointers to remove dependency on std::vector from public API .

For more info, see discussion at https://github.com/google/benchmark/pull/262#discussion_r72319678 .

* Move counter implementation from benchmark.cc to counter.cc.

    See discussion: https://github.com/google/benchmark/pull/262#discussion_r72298980 .

* Remove unused (commented-out) code.

* Moved thread counters to ThreadStats.

* Counters: fixed copy and move constructors.

* Counter: use an inplace buffer for small names.

* benchmark_test: move counters test out of CXX11 preprocessor conditional.

* Counter: fix VS2013 compilation error in char[] initialization.

* Fix typo.

* Expose counters from State.

See discussion: https://github.com/google/benchmark/pull/262#issuecomment-237156951

* Changed counters interface to map-like.

* Fix printing of user counters in ConsoleReporter.

* Applied clang-format to counter.cc and console_reporter.cc.

Command was `clang-format -style=Google -i counter.cc console_reporter.cc`
I also applied to all other files, but the changes were very
far-reaching so I rolled those back.

* Rename Counter::Flags_e to Counter::Flags

* Fix use of reserved names in Counter and BenchmarkCounters.

* Counter: Fix move ctor bug + change order of members.

* Fixture: remove tentative methods InitState() and TerminateState().

* Update fixture_test to the new Fixture interface.

* BenchmarkCounters: fixed a bug in the move ctor. Remove call to CHECK_LT().

CHECK_LT() was making the size_t lookup take ~double the time of a string lookup!

* BenchmarkCounters: add option to not print zero counters (defaults to false).

* Add test to compare counter storage and access with std::map.

* README: clarify cost of counter access modes.

* move counter access test to an own test.

* BenchmarkCounters: add move Insert()

* Counters access test: add accelerated lookup by name.

* Fix old range syntax.

* Fix missing include of cstdio

* Fix Visual Studio warning

* VS2013 and lower: fix use of snprintf()

* VS2013: fix use of char[] as a member of std::pair<>.

* change counter storage to std::map

* Remove skipZeroCounters logic

* Fix VS compilation error.

* Implemented request changes to PR #262.

* PR #262: More requested changes.

* README: cleanup counter text.

* PR #262: remove clang-format changes for preexisting code

* Complexity+Counters: fix counter flags which were being ignored.

* Document all Counter::Flag members

* fixed loss of counter values

* ConsoleReporter: remove tabular printing of user counters.

* ConsoleReporter: header printing should not be contingent on user counter names.

* Minor white space and alignment fixes.

* cxx03_test + counters: reuse the BM_empty() function.

* user counters: add note to README on how counters are gathered across threads
2017-03-01 17:23:42 -07:00
Marek Kurdej 0064c56abd Add tests for reporters (#307)
* Test bytes_per_second and items_per_second.

* Test SetLabel.

* Reformat.

* Make State::error_occurred_ private.

* Fix tests with floats.

* Merge private blocks
2016-10-28 09:13:57 -07:00
Marek Kurdej 3f23832a09 Allow calling Args and ArgNames in any order. 2016-10-26 09:36:39 +02:00
Marek Kurdej c1c01b2cd3 Handle the case when the argument name is an empty string. 2016-10-25 09:45:35 +02:00
Marek Kurdej 17e1c405dd Add ArgName() and ArgNames() methods to name arguments/ranges. 2016-10-24 09:57:40 +02:00
Marek Kurdej 8aeb20f16b Add tests. 2016-10-21 14:59:06 +02:00
Eric Fiselier 36a251ab3e Fix #300. Emit RMS as a float not a percentage in JSON 2016-10-07 22:26:01 -06:00
Eric Fiselier 2555035f44 Use correct RE for floating point numbers in reporter_output_test.cc 2016-10-07 21:56:22 -06:00
Dominic Hamon 1100e91907 Simplify clang-format and apply to tests (#302) 2016-10-07 11:04:50 -07:00
Ronny 72be9523bb Add Benchmark::ThreadRange() version with increment instead of multiply (#283)
* add additive thread range

* add test
2016-09-03 13:56:46 -06:00
Eric Fiselier 309ecb737f Increase complexity_test runtime slightly less. 2016-09-03 00:18:02 -06:00
Eric Fiselier 756f069918 Increase complexity_test.cc runtime to attempt to avoid appveyor failures 2016-09-03 00:06:51 -06:00
biojppm 83561f0580 CMake: add headers to the list of source files. (#284)
cmake does not require this, but IDEs such as VisualStudio or QtCreator
need this to add the headers to the generated project.
2016-08-31 15:28:43 -07:00
Eric 6e25917001 Add -DBENCHMARK_USE_LIBCXX:BOOL=<value> option. (#280)
* Add BENCHMARK_USE_LIBCXX option.

* Add comments

* re-add zero null pointer warning
2016-08-29 12:43:30 -06:00
Eric 49bbff2c66 Supply old `RangePair` and `ArgPair` API for C++03 compatibility. (#278)
* changes

* remove other changes

* remove unneeded test

* cleanup unused include
2016-08-29 10:59:46 -07:00
Eric Fiselier db1af86d16 Fix out-of-bounds std::vector access.
In the `Ranges(...)` generation code a "control" vector which stores
the current index for each range passed to `Ranges`. Previously this vector
was incorrectly initialized to the size of the subranges not the number
of subranges.

Additionally this patch suppresses unused warnings generated by
`stream_init_anchor`.
2016-08-28 23:07:38 -06:00
Eric Fiselier aaa25ac376 Improve diagnostic output for output tests. 2016-08-28 14:22:11 -06:00
Eric 0ed4456097 Refactor output test runner into standalone module. (#277)
* refactor

* Move default substitutions into library

* Move default substitutions to the *right* place in the library

* Fix init order issues that caused test failures

* improve diagnostics

* add missing include

* general cleanup

* Address review comments
2016-08-28 13:24:16 -06:00
Eric a11fb69c89 Add --benchmark_report_aggregates_only={true|false} flag for better summary output. (#267) 2016-08-10 18:20:54 -06:00
Eric Fiselier a7a7c56152 Workaround flaky complexity_test.cc test case.
See https://github.com/google/benchmark/issues/272
2016-08-09 14:14:15 -06:00
Eric Fiselier ee54a3f03e Rework Appveyor config
Currently the Appveyor bot is a PIT. It never passes and it often hangs
or gives very poor output. This patch rewrites the configuration.

This patch also attempts to fix a flaky complexity test as a drive-by.
2016-08-08 02:04:59 -06:00