# benchmark
[![Build Status](https://travis-ci.org/google/benchmark.svg?branch=master)](https://travis-ci.org/google/benchmark)
[![Build status](https://ci.appveyor.com/api/projects/status/u0qsyp7t1tk7cpxs/branch/master?svg=true)](https://ci.appveyor.com/project/google/benchmark/branch/master)
[![Coverage Status](https://coveralls.io/repos/google/benchmark/badge.svg)](https://coveralls.io/r/google/benchmark)
[![slackin](https://slackin-iqtfqnpzxd.now.sh/badge.svg)](https://slackin-iqtfqnpzxd.now.sh/)
A library to support the benchmarking of functions, similar to unit-tests.
Discussion group: https://groups.google.com/d/forum/benchmark-discuss
IRC channel: https://freenode.net #googlebenchmark
[Known issues and common problems](#known-issues)
[Additional Tooling Documentation](docs/tools.md)
[Assembly Testing Documentation](docs/AssemblyTests.md)
## Building
The basic steps for configuring and building the library look like this:
```bash
$ git clone https://github.com/google/benchmark.git
# Benchmark requires Google Test as a dependency. Add the source tree as a subdirectory.
$ git clone https://github.com/google/googletest.git benchmark/googletest
$ mkdir build && cd build
$ cmake -G <generator> [options] ../benchmark
# Assuming a makefile generator was used
$ make
```
Note that Google Benchmark requires Google Test to build and run the tests. This
dependency can be provided two ways:
* Checkout the Google Test sources into `benchmark/googletest` as above.
* Otherwise, if `-DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON` is specified during
configuration, the library will automatically download and build any required
dependencies.
If you do not wish to build and run the tests, add `-DBENCHMARK_ENABLE_GTEST_TESTS=OFF`
to `CMAKE_ARGS`.
## Installation Guide
For Ubuntu and Debian Based System
First make sure you have git and cmake installed (If not please install it)
```
sudo apt-get install git
sudo apt-get install cmake
```
Now, let's clone the repository and build it
```
git clone https://github.com/google/benchmark.git
cd benchmark
git clone https://github.com/google/googletest.git
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=RELEASE
make
```
We need to install the library globally now
```
sudo make install
```
Now you have google/benchmark installed in your machine
Note: Don't forget to link to pthread library while building
## Stable and Experimental Library Versions
The main branch contains the latest stable version of the benchmarking library;
the API of which can be considered largely stable, with source breaking changes
being made only upon the release of a new major version.
Newer, experimental, features are implemented and tested on the
[`v2` branch](https://github.com/google/benchmark/tree/v2). Users who wish
to use, test, and provide feedback on the new features are encouraged to try
this branch. However, this branch provides no stability guarantees and reserves
the right to change and break the API at any time.
##Prerequisite knowledge
Before attempting to understand this framework one should ideally have some familiarity with the structure and format of the Google Test framework, upon which it is based. Documentation for Google Test, including a "Getting Started" (primer) guide, is available here:
https://github.com/google/googletest/blob/master/googletest/docs/Documentation.md
## Example usage
### Basic usage
Define a function that executes the code to be measured.
```c++
#include <benchmark/benchmark.h>
static void BM_StringCreation(benchmark::State& state) {
for (auto _ : state)
std::string empty_string;
}
// Register the function as a benchmark
BENCHMARK(BM_StringCreation);
// Define another benchmark
static void BM_StringCopy(benchmark::State& state) {
std::string x = "hello";
for (auto _ : state)
std::string copy(x);
}
BENCHMARK(BM_StringCopy);
BENCHMARK_MAIN();
```
Don't forget to inform your linker to add benchmark library e.g. through
`-lbenchmark` compilation flag. Alternatively, you may leave out the
`BENCHMARK_MAIN();` at the end of the source file and link against
`-lbenchmark_main` to get the same default behavior.
The benchmark library will reporting the timing for the code within the `for(...)` loop.
### Passing arguments
Sometimes a family of benchmarks can be implemented with just one routine that
takes an extra argument to specify which one of the family of benchmarks to
run. For example, the following code defines a family of benchmarks for
measuring the speed of `memcpy()` calls of different lengths:
```c++
static void BM_memcpy(benchmark::State& state) {
char* src = new char[state.range(0)];
char* dst = new char[state.range(0)];
memset(src, 'x', state.range(0));
for (auto _ : state)
memcpy(dst, src, state.range(0));
state.SetBytesProcessed(int64_t(state.iterations()) *
int64_t(state.range(0)));
delete[] src;
delete[] dst;
}
BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10);
```
The preceding code is quite repetitive, and can be replaced with the following
short-hand. The following invocation will pick a few appropriate arguments in
the specified range and will generate a benchmark for each such argument.
```c++
BENCHMARK(BM_memcpy)->Range(8, 8<<10);
```
By default the arguments in the range are generated in multiples of eight and
the command above selects [ 8, 64, 512, 4k, 8k ]. In the following code the
range multiplier is changed to multiples of two.
```c++
BENCHMARK(BM_memcpy)->RangeMultiplier(2)->Range(8, 8<<10);
```
Now arguments generated are [ 8, 16, 32, 64, 128, 256, 512, 1024, 2k, 4k, 8k ].
You might have a benchmark that depends on two or more inputs. For example, the
following code defines a family of benchmarks for measuring the speed of set
insertion.
```c++
static void BM_SetInsert(benchmark::State& state) {
std::set<int> data;
for (auto _ : state) {
state.PauseTiming();
data = ConstructRandomSet(state.range(0));
state.ResumeTiming();
for (int j = 0; j < state.range(1); ++j)
data.insert(RandomNumber());
}
}
BENCHMARK(BM_SetInsert)
->Args({1<<10, 128})
->Args({2<<10, 128})
->Args({4<<10, 128})
->Args({8<<10, 128})
->Args({1<<10, 512})
->Args({2<<10, 512})
->Args({4<<10, 512})
->Args({8<<10, 512});
```
The preceding code is quite repetitive, and can be replaced with the following
short-hand. The following macro will pick a few appropriate arguments in the
product of the two specified ranges and will generate a benchmark for each such
pair.
```c++
BENCHMARK(BM_SetInsert)->Ranges({{1<<10, 8<<10}, {128, 512}});
```
For more complex patterns of inputs, passing a custom function to `Apply` allows
programmatic specification of an arbitrary set of arguments on which to run the
benchmark. The following example enumerates a dense range on one parameter,
and a sparse range on the second.
```c++
static void CustomArguments(benchmark::internal::Benchmark* b) {
for (int i = 0; i <= 10; ++i)
for (int j = 32; j <= 1024*1024; j *= 8)
b->Args({i, j});
}
BENCHMARK(BM_SetInsert)->Apply(CustomArguments);
```
### Calculate asymptotic complexity (Big O)
Asymptotic complexity might be calculated for a family of benchmarks. The
following code will calculate the coefficient for the high-order term in the
running time and the normalized root-mean square error of string comparison.
```c++
static void BM_StringCompare(benchmark::State& state) {
std::string s1(state.range(0), '-');
std::string s2(state.range(0), '-');
for (auto _ : state) {
benchmark::DoNotOptimize(s1.compare(s2));
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(BM_StringCompare)
->RangeMultiplier(2)->Range(1<<10, 1<<18)->Complexity(benchmark::oN);
```
As shown in the following invocation, asymptotic complexity might also be
calculated automatically.
```c++
BENCHMARK(BM_StringCompare)
->RangeMultiplier(2)->Range(1<<10, 1<<18)->Complexity()
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
TensorRT-使用tensorrt在GPU上部署CenterNet-优质算法部署项目实战.zip (2000个子文件)
protoc-gen-mypy.bat 45B
onnxifi_wrapper.c 28KB
onnxifi_dummy.c 5KB
onnxifi_loader.c 5KB
implementation.cc 14KB
cpp2py_export.cc 11KB
test.cc 9KB
test.cc 9KB
test.cc 6KB
test.cc 6KB
convert.cc 4KB
protobuf-bench.cc 4KB
helper.cc 3KB
.clang-format 3KB
unittest.cmake 3KB
summary.cmake 2KB
Utils.cmake 1KB
googletest.cmake 1KB
CODEOWNERS 469B
nv_onnx_parser_bindings_wrap.cpp 189KB
builtin_op_importers.cpp 166KB
onnx2trt_utils.cpp 57KB
onnx_trt_backend.cpp 35KB
ModelImporter.cpp 28KB
test_methods_and_attributes.cpp 23KB
test_virtual_functions.cpp 17KB
test_class.cpp 17KB
test_eigen.cpp 16KB
test_smart_ptr.cpp 16KB
test_numpy_dtypes.cpp 16KB
test_factory_constructors.cpp 16KB
test_numpy_array.cpp 15KB
pose_infer.cpp 14KB
test_infer.cpp 14KB
test_infer.cpp 14KB
test_sequences_and_iterators.cpp 13KB
test_stl.cpp 11KB
main.cpp 11KB
ShapeTensor.cpp 11KB
test_interpreter.cpp 10KB
test_pytypes.cpp 9KB
OnnxAttrs.cpp 9KB
test_copy_move.cpp 9KB
test_builtin_casters.cpp 9KB
test_multiple_inheritance.cpp 9KB
plugin.cpp 7KB
test_exceptions.cpp 7KB
test_operator_overloading.cpp 6KB
getSupportedAPITest.cpp 6KB
test_callbacks.cpp 6KB
test_buffers.cpp 6KB
pybind11_cross_module_tests.cpp 5KB
ctdet_infer.cpp 5KB
test_pickling.cpp 5KB
test_local_bindings.cpp 4KB
test_tagbased_polymorphic.cpp 4KB
test_kwargs_and_defaults.cpp 4KB
test_constants_and_functions.cpp 4KB
ShapedWeights.cpp 4KB
pybind11_tests.cpp 4KB
test_numpy_vectorize.cpp 4KB
test_call_policies.cpp 4KB
test_stl_binders.cpp 3KB
test_modules.cpp 3KB
custom.cpp 3KB
dcn_v2_cpu.cpp 3KB
test_enum.cpp 3KB
test_opaque_types.cpp 3KB
test_eval.cpp 2KB
test_docstring_options.cpp 2KB
PluginFactory.cpp 2KB
test_iostream.cpp 2KB
test_chrono.cpp 2KB
cross_module_gil_utils.cpp 2KB
test_gil_scoped.cpp 2KB
builtin_plugins.cpp 2KB
NvOnnxParser.cpp 2KB
NvOnnxParserRuntime.cpp 1KB
logger.cpp 1KB
logger.cpp 1KB
logger.cpp 1KB
ResizeBind.cpp 1KB
test_async.cpp 863B
topk_cpu.cpp 710B
embed.cpp 654B
catch.cpp 637B
test_union.cpp 603B
external_module.cpp 554B
vision.cpp 466B
posix_regex.cpp 297B
gnu_posix_regex.cpp 267B
std_regex.cpp 259B
main.cpp 152B
steady_clock.cpp 136B
thread_safety_attributes.cpp 79B
theme_overrides.css 254B
decode.cu 21KB
dcn_v2_im2col_cuda.cu 10KB
dcn_v2_im2col_cuda.cu 10KB
dcn_v2.cu 8KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
__AtYou__
- 粉丝: 3447
- 资源: 2134
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功