Commit Graph

123 Commits

Author SHA1 Message Date
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
Disconnect3d
2a05f248be Improve README's basic usage example (#433) 2017-09-14 09:31:35 +02:00
Andre Schroeder
24b8042733 Fix Markdown typos in readme. (#445) 2017-09-13 15:42:45 -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
Joao Paulo Magalhaes
615151723e Merge remote-tracking branch 'upstream/master' into compact 2017-05-02 18:54:37 +01:00
Joao Paulo Magalhaes
707dd89344 User counters: document tabular output in README.md 2017-04-01 22:31:39 +01: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
Eric
f682f7e9a4 Implement ClobberMemory() and fix DoNotOptimize on MSVC. (#352)
I recently learned Windows provides a function called _ReadWriteBarrier
which is literally ClobberMemory under a different name. This patch
uses it to implement ClobberMemory under MSVC.
2017-03-10 18:47:39 -07: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
Eric
83ac086fbd Add compare_bench.py documentation. Fixes #309 (#318) 2016-12-02 19:47:27 -07:00
Dominic Hamon
62c68ba4f0 s/resolved/unresolved/ 2016-09-23 12:44:22 -07:00
Eric Fiselier
9c26168126 Document --benchmark_filter. Thanks to NAThompson for the original patch 2016-09-05 15:40:12 -06:00
Eric Fiselier
07ee194092 Fix wording because an idiot came up with it. 2016-09-03 00:19:37 -06:00
Eric Fiselier
61f570e82a Fix #202 - Document Windows dependency on shlwapi.lib 2016-08-30 03:41:58 -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
de4ead7a53 Document compiler requirements (#269) 2016-08-09 12:31:44 -06:00
Eric Fiselier
9820035998 Whitespace change to trigger appveyor. 2016-08-07 16:31:43 -06:00
Marcin Kolny
dfe0260754 Support multiple ranges in the benchmark (#257)
* Support multiple ranges in the benchmark

google-benchmark library allows to provide up to two ranges to the
benchmark method (range_x and range_y). However, in many cases it's not
sufficient. The patch introduces multi-range features, so user can easily
define multiple ranges by passing a vector of integers, and access values
through the method range(i).

* Remove redundant API

Functions State::range_x() and State::range_y() have been removed. They should
be replaced by State::range(0) and State::range(1).
Functions Benchmark::ArgPair() and Benchmark::RangePair() have been removed.
They should be replaced by Benchmark::Args() and Benchmark::Ranges().
2016-08-04 12:30:14 -07:00
Eric
5f5ca31ce0 Add RegisterBenchmark(name, func, args...) for creating/registering benchmarks. (#259)
* Add RegisterBenchmark

* fix test inputs

* fix UB caused by unitialized value

* Add RegisterBenchmark

* fix test inputs

* fix UB caused by unitialized value

* Work around GCC 4.6/4.7/4.8 bug
2016-08-02 16:22:46 -07:00
Eric Fiselier
44128d87d2 Add --benchmark_out=<filename> and --benchmark_out_format=<format> options.
These options allow you to write the output of a benchmark to the specified
file and with the specified format. The goal of this change is to help support
tooling.
2016-08-02 15:12:43 -06:00
Eric Fiselier
7e40ff9e35 Provide a better implementation of DoNotOptimize(...).
This implementation is less likely to ICE compilers, and is more correct.
It also acts as a memory barrier which will help prevent writes to global memory
from being optimized away.
2016-07-11 14:58:50 -06:00
Nick
d147797aac Add state.SetComplexityN to docs. (#245)
Add `state.SetComplexityN(state.range_x());` to documentation so that complexity is calculated correctly.
2016-06-27 11:24:13 -07:00
Ryan
1d53e5e0d8 Clarified output formats (#241) 2016-06-20 09:15:09 -07:00
Ismael
240ba4e64e changed BigOFunc argument from size_t to int 2016-06-02 22:21:52 +02:00
Ismael
3ef6339971 Update Readme.md 2016-06-02 20:58:14 +02:00
Eric
238e558fdb Allow benchmarks to take arbitrary arguments. (#221)
* Add lambda benchmarks

* Remove lambda capture since the lambda is not at a block scope

* Remove LambdaBenchmark helper since FunctionBenchmark can be used with non-capturing lambas

* Add lambda benchmarks

* Remove lambda capture since the lambda is not at a block scope

* Remove LambdaBenchmark helper since FunctionBenchmark can be used with non-capturing lambas

* Add more docs for BENCHMARK_CAPTURE.

* Fix use of misnamed parameter

* Guard BENCHMARK_CAPTURE tests against non-c++11 compilers

* Move tests out of basic_test.cc
2016-05-27 12:37:10 -07:00
Dominic Hamon
d6bc7e1581 Merge branch 'update_complexity' of git://github.com/ismaelJimenez/benchmark into ismaelJimenez-update_complexity 2016-05-26 14:01:28 -07:00
Ismael
90a8508063 Update Readme.md 2016-05-25 23:06:27 +02:00
Dominic Hamon
9686f1769e Merge branch 'skip_with_error' of git://github.com/efcs/benchmark into efcs-skip_with_error 2016-05-25 09:00:31 -07:00
Eric Fiselier
84bc4d703b Add a per benchmark 'Repetitions' option. 2016-05-24 21:52:23 -06:00
Eric Fiselier
924b8cee7a Reflow some wording. NFC 2016-05-24 15:21:41 -06:00
Eric Fiselier
bdeb38718e merge 2016-05-24 15:01:07 -06:00
Dominic Hamon
2440b752fd Formatting updates 2016-05-24 13:26:32 -07:00
Eric Fiselier
90c9ab1d8e add doc 2016-05-23 20:35:09 -06:00
Ismael
ac05c04533 refactor MinimalLEastSq 2016-05-23 20:12:54 +02:00
Ismael
07efafbf5c Update Readme 2016-05-21 16:34:12 +02:00
Ismael
dc667d0486 Added asymptotic complexity to Readme 2016-05-21 12:40:27 +02:00
Ismael
5812d545ef Added range multiplier to Readme 2016-05-21 12:16:40 +02:00
Jussi Knuuttila
e253a28402 Manual timing support. 2016-05-05 23:24:13 +03:00
Kai Wolf
f352c30f1c Merge branch 'master' into feature/add-ms-time-report 2016-04-29 21:42:21 +02:00
Dominic Hamon
d6f96ed639 Add section on iterations.
Also add some subheadings, and fix up the line lengths.

Fixes #194
2016-04-19 09:34:13 -07:00
Kai Wolf
0b4111c3b3 Refactor GetTimeUnitAndMultiplier and add example 2016-03-28 21:32:11 +02:00
Arkady Shapkin
8da907c2c2 Update README.md 2016-02-16 23:29:24 +03:00
Dominic Hamon
211f23ee13 Add section on optimisations to README 2016-02-14 09:28:10 -08:00
Eli Bendersky
c7ab1b987b Update README to mention UseRealTime for wallclock time measurements.
Also adding a use case in the API header.

Fixes #170
2015-12-30 06:01:19 -08:00
Dominik Czarnota
d2917bcded Fixes #165: CustomArguments ret type in README
* adds myself to AUTHORS/CONTRIBUTORS
2015-11-30 16:15:00 +01:00
Dominic Hamon
4499e8e415 Fixes #161 2015-11-05 09:53:08 -08:00
Dominic Hamon
559c71d840 Added IRC channel to README.md 2015-10-13 12:02:08 -07:00
Eli Bendersky
f338ce7965 Fix doc sample typos in header and README
* iterations() is a method
* int64_t fix in a couple of places
2015-09-17 20:14:10 -07:00
Dominic Hamon
d8c7605341 Update README.md 2015-05-12 11:32:44 -07:00
Dominic Hamon
375e66c825 Update README.md 2015-05-11 12:34:03 -07:00
Eric Fiselier
9ed538f511 address review comments 2015-04-06 17:56:05 -04:00
David Reynolds
30ae37b923 Fix typos: rangeY -> range_y() 2015-04-02 18:34:52 -07:00
Dominic Hamon
9934396e1f Add missing paranthesis and documentation 2015-04-01 10:51:37 -04:00
Eric Fiselier
e428b9eec3 Add 'benchmark::DoNotOptimize(...)' to help users prevent optimizations 2015-03-27 16:35:46 -04:00
Eric Fiselier
daa8a67aa5 add C++03 test and update README 2015-03-18 16:34:43 -04:00
Eric Fiselier
ffb67dcabf address review comments 2015-03-17 18:42:41 -04:00
Dominic Hamon
bdf4a5f4d2 Add reference to BENCHMARK_MAIN in README 2015-03-12 21:56:45 -07:00
Dominic Hamon
fd7d288bbe Add section on linking to satisfy #67 2014-12-26 08:44:14 -08:00
Dominic Hamon
2aa2442024 Remove drone.io reference 2014-12-02 12:46:27 -08:00
Dominic Hamon
d58d59588f Merge pull request #66 from 3Hren/master
Using Travis CI.
2014-11-14 14:19:16 -08:00
Evgeny Safronov
6f692460e7 Update readme.
Added Travis build status badge.
2014-11-14 11:11:45 +04:00
Dominic Hamon
4932b72b03 Fix example in README.md to compile.
Fixes #65
2014-11-13 13:06:28 -08:00
Paul Redmond
0ce150e1fc fix examples to use SetBytesProcessed
- use State::SetBytesProcessed not SetBenchmarkBytesProcessed
2014-07-23 13:42:04 -04:00
Chris Seymour
465cb09eb6 Update README.md
Switched to language specific markdown for code sections to provide syntax highlighting when rendered.
2014-02-09 19:45:17 +00:00
Oleksandr
a278152117 Fix int64_t_t typo in README code example
Fixes a typo where the first type was written as int64_t_t with suffixing _t twice and the second type misses suffix at all.
2014-01-15 23:01:47 +02:00
Dominic Hamon
96446f2f5a Add discussion group to README.md 2014-01-09 10:48:18 -08:00
Dominic Hamon
373a7ddf90 Add drone.io build badge to README.md 2014-01-07 17:04:19 -08:00
Dominic Hamon
2d557f1c75 Add Threads registration example to README.md 2014-01-07 13:48:27 -08:00
Dominic Hamon
80162cab32 Update README.md 2013-12-20 14:53:25 -08:00
Dominic Hamon
01af2bc857 Create README.md 2013-12-20 14:51:56 -08:00