# 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()
没有合适的资源?快使用搜索试试~ 我知道了~
MXNET 1.9.1源码
共2000个文件
h:731个
py:684个
md:275个
需积分: 5 1 下载量 60 浏览量
2023-11-01
10:22:39
上传
评论
收藏 497.47MB ZIP 举报
温馨提示
mxnet 1.9.1源码,可以在rk3588上成功编译
资源推荐
资源详情
资源评论
收起资源包目录
MXNET 1.9.1源码 (2000个子文件)
utvm_runtime.c 4KB
utvm_timer.c 3KB
utvm_device_dylib_redirect.c 2KB
utvm_timer.c 1KB
numpy_dlpack.c 1KB
utvm_init.c 1KB
mock_c.c 166B
charRNN.cpp 29KB
imagenet_inference.cpp 23KB
sentiment_analysis_rnn.cpp 17KB
alexnet.cpp 14KB
inception_bn.cpp 10KB
mlp_csv.cpp 10KB
resnet.cpp 9KB
lenet.cpp 9KB
googlenet.cpp 8KB
lenet_with_mxdataiter.cpp 7KB
test_kvstore.cpp 6KB
mlp.cpp 6KB
test_score.cpp 5KB
mlp_gpu.cpp 5KB
gen_warp.cpp 5KB
mlp_cpu.cpp 5KB
feature_extract.cpp 4KB
warp_dll.cpp 3KB
test_regress_label.cpp 2KB
test_ndarray_copy.cpp 2KB
prepare_data_with_opencv.cpp 2KB
test_optimizer.cpp 1KB
array_test.go 14KB
function.go 12KB
value.go 12KB
ndarray.go 12KB
function_test.go 9KB
value_test.go 7KB
complex.go 5KB
module.go 4KB
context.go 4KB
bytearray.go 3KB
module_test.go 3KB
simple.go 2KB
type.go 2KB
pack_func_closure_return.go 2KB
pack_func_closure_arg.go 2KB
pack_func_register.go 2KB
pack_func_handle_arg.go 2KB
pack_func_convert.go 2KB
bytearray_test.go 1KB
error.go 1KB
gotvm.go 1KB
gotvm_test.go 1KB
error_test.go 1KB
util.go 1KB
c_api.h 147KB
matrix_op-inl.h 114KB
optimizer_op-inl.h 110KB
rnn_impl.h 88KB
broadcast_reduce_op.h 74KB
linalg_impl.h 72KB
pool.h 71KB
rnn-inl.h 67KB
indexing_op.h 62KB
dot-inl.h 60KB
np_matrix_op-inl.h 54KB
lib_api.h 53KB
ndarray.h 53KB
mxnet_op.h 49KB
mshadow_op.h 49KB
packed_func.h 47KB
nn.h 45KB
transform.h 45KB
ordering_op-inl.h 45KB
imperative_utils.h 44KB
bounding_box-inl.h 42KB
la_op-inl.h 41KB
np_broadcast_reduce_op.h 41KB
np_einsum_op-inl.h 40KB
cudnn_deconvolution-inl.h 40KB
elemwise_binary_op.h 39KB
profiler.h 39KB
cudnn_convolution-inl.h 39KB
pooling.h 39KB
la_op.h 39KB
image_random-inl.h 39KB
expr.h 37KB
elemwise_binary_broadcast_op.h 37KB
elemwise_unary_op.h 36KB
gpu_topology.h 36KB
fused_op-inl.h 35KB
softmax-inl.h 35KB
packed_func.h 35KB
ibverbs_van.h 35KB
kvstore_dist.h 33KB
np_norm-inl.h 33KB
np_einsum_path_op-inl.h 33KB
np_pinv-inl.h 31KB
np_tensordot_op-inl.h 31KB
utils.h 30KB
comm.h 30KB
sample_op.h 30KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
呆呆珝
- 粉丝: 1w+
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功