Commit Graph

900 Commits

Author SHA1 Message Date
Yangqing Jia 105ac14b2f Add caching for cxx_feature_check (#573) 2018-04-23 20:57:03 +01:00
Victor Costan 64d4805dd7 Fix precision loss warning in MSVC. (#574) 2018-04-23 11:58:02 +01:00
Dominic Hamon c4858d8012
Report the actual iterations run. (#572)
Before this change, we would report the number of requested iterations
passed to the state. After, we will report the actual number run. As a
side-effect, instead of multiplying the expected iterations by the
number of threads to get the total number, we can report the actual
number of iterations across all threads, which takes into account the
situation where some threads might run more iterations than others.
2018-04-19 18:40:08 +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
Fred Tingaud 50ffc781b1 Optimize by using nth_element instead of partial_sort to find the median. (#565) 2018-04-09 13:40:58 +01:00
Eric Fiselier 2844167ff9 Fix #564 - gmock/gmock.h not found in benchmark tests. 2018-04-05 18:34:13 -06: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 e668e2a1ba Fix #552 - GCC and Clang warn on possibly invalid offsetof usage.
This patch disables the -Winvalid-offsetof warning for GCC and Clang
when using it to check the cache lines of the State object.

Technically this usage of offsetof is undefined behavior until C++17.
However, all major compilers support this application as an extension,
as demonstrated by the passing static assert (If a compiler encounters UB
during evaluation of a constant expression, that UB must be diagnosed).
Unfortunately, Clang and GCC also produce a warning about it.

This patch temporarily suppresses the warning using #pragma's in the
source file (instead of globally suppressing the warning in the build systems).
This way the warning is ignored for both CMake and Bazel builds without
having to modify either build system.
2018-03-21 13:47:25 -06: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
Dominic Hamon 674d0498b8
Move thread classes out to clean up monolithic code (#554) 2018-03-16 10:14:38 +00: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
Wink Saville 61497236dd Make string_util naming more consistent (#547)
* Rename StringXxx to StrXxx in string_util.h and its users

This makes the naming consistent within string_util and moves is the
Abseil convention.

* Style guide is 2 spaces before end of line "//" comments

* Rename StrPrintF/StringPrintF to StrFormat for absl compatibility.
2018-03-07 11:20:06 +00:00
Wink Saville f48a28d12a Do not let StrCat be renamed to lstrcatA (#546)
On Windows the Shlwapi.h file has a macro:

  #define StrCat lstrcatA

And benchmark/src/string_util.h defines StrCat and it is renamed to
lstrcatA if we don't undef the macro in Shlwapi.h. This is an innocuous
bug if string_util.h is included after Shlwapi.h, but it is a compile
error if string_util.h is included before Shlwapi.h.

This fixes issue #545.
2018-03-06 18:15:03 +00:00
Wink Saville 69a52cff4f Spelling fixes (#543)
Upstream spelling fix changes from Pony, ec47ba8f565726414552f4bbf97d7,
by ka7@la-evento.com that effected google/benchmark.
2018-03-06 11:44:25 +00:00
alekseyshl 47df49e573 Add Solaris support (#539)
* Add Solaris support

Define BENCHMARK_OS_SOLARIS for Solaris.

Platform specific implementations added:
* number of CPUs detection
* CPU cycles per second detection
* Thread CPU usage
* Process CPU usage

* Remove the special case for per process CPU time for Solaris, it's the same as the default.
2018-03-02 03:53:58 -08:00
Robert Guo ff2c255af5 Use STCK to get the CPU clock on s390x (#540) 2018-03-02 03:22:03 -08: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
Jonathan Wakely e9a49be7f1 Update note about linking with pthreads (#536) 2018-02-21 08:42:16 -08:00
Jonathan Wakely 19048b7b65 Fix typo in README.md (#535) 2018-02-21 08:41:52 -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
Ian McKellar 6ecf8a8e80 Don't include <sys/resource.h> on Fuchsia. (#531)
* Don't include <sys/resource.h> on Fuchsia.

It doesn't support POSIX resource measurement and timing APIs.

Change-Id: Ifab4bac4296575f042c699db1ce5a4f7c2d82893

* Add BENCHMARK_OS_FUCHSIA for Fuchsia

Change-Id: Ic536f9625e413270285fbfd08471dcb6753ddad1
2018-02-14 14:17:12 -07:00
Eric 207b9c7aec
Improve State packing: put important members on first cache line. (#527)
* Improve State packing: put important members on first cache line.

This patch does a few different things to ensure commonly accessed
data is on the first cache line of the `State` object.

First, it moves the `error_occurred_` member to reside after
the `started_` and `finished_` bools, since there was internal
padding there that was unused.

Second, it moves `batch_leftover_` and `max_iterations` further up
in the struct declaration. These variables are used in the calculation
of `iterations()` which users might call within the loop. Therefore
it's more important they exist on the first cache line.

Finally, this patch turns the bool members into bitfields. Although
this shouldn't have much of an effect currently, because padding is
still needed between the last bool and the first size_t, it should
help in future changes that require more "bool like" members.

* Remove bitfield change for now

* Move bools (and their padding) to end of "first cache line" vars.

I think it makes the most sense to move the padding required
following the group of bools to the end of the variables we want
on the first cache line.

This also means that the `total_iterations_` variable, which is the
most accessed, has the same address as the State object.

* Fix static assertion after moving bools
2018-02-14 13:44:41 -07:00
Samuel Panzer 3924ee7b8a Fixups following addition of KeepRunningBatch (296ec5693) (#526)
* 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()

* Implement KeepRunning() in terms of KeepRunningBatch().

* Improve codegen by helping the compiler undestand dead code.

* Dummy commit for build bots' benefit.
2018-02-13 13:54:46 -07:00
Eric 37dbe80f9b
Attempt to fix travis timeouts during apt-get. (#528)
* Attempt to fix travis timeouts during apt-get.

During some builds, travis fails to update the apt-get indexes.
This causes the build to fail in different ways.

This patch attempts to avoid this issue by manually calling
apt-get update. I'm not sure if it'll work, but it's worth a try.

* Fix missing semicolons in command
2018-02-12 21:28:23 -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
Eric Fiselier 562f9d256d Fix GTest workaround on MSVC 2018-02-12 18:43:32 -07:00
Eric 906749a48e Work around Gtest build failure caused by -Werror=unused-function. (#529)
We're propagating extra warning flags to the gtest build, which
can cause it to fail. This patch prevents passing "-Wextra" to
gtest, since the library itself doesn't test with that flag.
2018-02-12 17:11:01 -08: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
Tim bc83262f9d .vs/ and CmakeSettings.json to gitignore (#522) 2018-02-03 22:04:36 -07:00
Dominic Hamon df415adb2a
Some small clang-tidy fixes (#520) 2018-01-29 08:38:47 -08:00
oskidan 4fe0206b65 Fixes compilation error caused by integer precision loss due to implicit (#518)
conversion in sysinfo.cc
2018-01-19 09:17:01 -08:00
Dominic Hamon 9f5694ceb6
Wrap COMPILER macros. (#514)
Some command line or build systems may already set these (eg, bazel) so
make sure that takes priority.

Fixes #513
2018-01-11 17:22:45 -08:00
Eric e1c3a83b81
Merge pull request #509 from efcs/fix-gtest-install
Prevent GTest and GMock from being installed with Google Benchmark.
2018-01-05 12:51:03 -07:00
Eric Fiselier 778b85a7a9 Prevent GTest and GMock from being installed with Google Benchmark.
When users satisfy the GTest dependancy by placing a googletest
directory in the project, the targets from GTest and GMock incorrectly
get installed along side this library. We shouldn't be installing
our test dependancies.

This patch forces the options that control installation for googletest
to OFF.
2018-01-05 11:04:22 -07:00
Winston Du 052421c823 Updated documentation. (#503)
For people who get this library via CMake's AddExternalProject like me.
Would like a long term tutorial from someone who really understands CMake on how to actually link an externalproject's dependencies to another added external project.
2018-01-04 17:13:34 -07:00
Dominic Hamon e4ccad7c4a
Update README.md 2017-12-14 09:40:26 -08: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
Eric Fiselier de725e5a7c Document new 'v2' branch meant for unstable development.
This patch documents the newly added v2 branch, which will
be used to stage, test, and receive feedback on upcoming
features, most of which will be breaking changes which can't
be directly applied to master.
2017-12-13 14:51:56 -07:00
Dominic Hamon 7f2d2cd5b9 fix xcode travis builds by skipping mkdir errors 2017-12-07 14:20:59 -08:00
Louis Dionne 5b2c08668c Enforce using a semicolon after BENCHMARK_MAIN to remove compiler warnings (#495) 2017-12-03 18:45:07 -07:00
Victor Costan 0bbaeeaf7a Add GCC on OSX to list of Travis CI configurations. (#492) 2017-11-30 15:21:32 -08:00
Victor Costan 95a1435b81 Fix compilation error with GCC on OSX (issue #490). (#491) 2017-11-30 08:05:38 -08:00
Roman Lebedev c45f01866b CMake: implement LTO for clang. Fixes #478 (#487)
* CMake: implement LTO for clang. Fixes #478

* LTO: add basic docs about required executables.
2017-11-29 12:48:43 -08:00
Kishan Kumar eae42212ce Added the installation guide for Ubuntu (#489)
* Initial CLA Requirement

* Added Installation steps to the Readme.md

* Fixed error in running benchmark of Installation

* Remove unwanted commands

Removed the lengthy install procedure with suggested install mechanism
2017-11-29 09:36:19 -08:00
Roman Lebedev ec5684ed75 Console reporter: properly account for the lenght of custom counter names (#484)
Old output example:
```
Benchmark                                                 Time           CPU Iterations  CPUTime,s   Pixels/s ThreadingFactor
------------------------------------------------------------------------------------------------------------------------------
20170525_0036TEST.RAF/threads:8/real_time                45 ms         45 ms         16   0.718738 79.6277M/s   0.999978   2.41419GB/s    22.2613 items/s FileSize,MB=111.050781; MPix=57.231360
```

New output example:
```
Benchmark                                                 Time           CPU Iterations  CPUTime,s   Pixels/s ThreadingFactor
------------------------------------------------------------------------------------------------------------------------------
20170525_0036TEST.RAF/threads:8/real_time                45 ms         45 ms         16   0.713575 80.1713M/s        0.999571   2.43067GB/s    22.4133 items/s FileSize,MB=111.050781; MPix=57.231360
```
2017-11-27 09:01:01 -08:00
Eric Fiselier 2ec7399cf1 Improve BENCHMARK_UNREACHABLE() implementation.
This patch primarily changes the BENCHMARK_UNREACHABLE()
implementation under MSVC to use __assume(false) instead
of being a NORETURN function, which ironically caused
unreachable code warnings.

Second, since the NOTHROW function attempt generated the
warnings we meant to avoid, it has been replaced with a dummy
null statement.
2017-11-26 13:58:24 -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