benchmark
=========
[![Build Status](https://travis-ci.org/google/benchmark.svg?branch=master)](https://travis-ci.org/google/benchmark)
A library to support the benchmarking of functions, similar to unit-tests.
Discussion group: https://groups.google.com/d/forum/benchmark-discuss
Example usage
-------------
Define a function that executes the code to be measured a
specified number of times:
```c++
static void BM_StringCreation(benchmark::State& state) {
while (state.KeepRunning())
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";
while (state.KeepRunning())
std::string copy(x);
}
BENCHMARK(BM_StringCopy);
BENCHMARK_MAIN();
```
Sometimes a family of microbenchmarks 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 microbenchmarks for measuring the speed
of `memcpy()` calls of different lengths:
```c++
static void BM_memcpy(benchmark::State& state) {
char* src = new char[state.range_x()]; char* dst = new char[state.range_x()];
memset(src, 'x', state.range_x());
while (state.KeepRunning())
memcpy(dst, src, state.range_x());
state.SetBytesProcessed(int64_t(state.iterations) * int64_t(state.range_x()));
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
microbenchmark for each such argument.
```c++
BENCHMARK(BM_memcpy)->Range(8, 8<<10);
```
You might have a microbenchmark that depends on two inputs. For
example, the following code defines a family of microbenchmarks for
measuring the speed of set insertion.
```c++
static void BM_SetInsert(benchmark::State& state) {
while (state.KeepRunning()) {
state.PauseTiming();
std::set<int> data = ConstructRandomSet(state.range_x());
state.ResumeTiming();
for (int j = 0; j < state.rangeY; ++j)
data.insert(RandomNumber());
}
}
BENCHMARK(BM_SetInsert)
->ArgPair(1<<10, 1)
->ArgPair(1<<10, 8)
->ArgPair(1<<10, 64)
->ArgPair(1<<10, 512)
->ArgPair(8<<10, 1)
->ArgPair(8<<10, 8)
->ArgPair(8<<10, 64)
->ArgPair(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 microbenchmark for each such pair.
```c++
BENCHMARK(BM_SetInsert)->RangePair(1<<10, 8<<10, 1, 512);
```
For more complex patterns of inputs, passing a custom function
to Apply allows programmatic specification of an
arbitrary set of arguments to run the microbenchmark on.
The following example enumerates a dense range on one parameter,
and a sparse range on the second.
```c++
static benchmark::internal::Benchmark* CustomArguments(
benchmark::internal::Benchmark* b) {
for (int i = 0; i <= 10; ++i)
for (int j = 32; j <= 1024*1024; j *= 8)
b = b->ArgPair(i, j);
return b;
}
BENCHMARK(BM_SetInsert)->Apply(CustomArguments);
```
Templated microbenchmarks work the same way:
Produce then consume 'size' messages 'iters' times
Measures throughput in the absence of multiprogramming.
```c++
template <class Q> int BM_Sequential(benchmark::State& state) {
Q q;
typename Q::value_type v;
while (state.KeepRunning()) {
for (int i = state.range_x(); i--; )
q.push(v);
for (int e = state.range_x(); e--; )
q.Wait(&v);
}
// actually messages, not bytes:
state.SetBytesProcessed(
static_cast<int64_t>(state.iterations())*state.range_x());
}
BENCHMARK_TEMPLATE(BM_Sequential, WaitQueue<int>)->Range(1<<0, 1<<10);
```
Three macros are provided for adding benchmark templates.
```c++
#if __cplusplus >= 201103L // C++11 and greater.
#define BENCHMARK_TEMPLATE(func, ...) // Takes any number of parameters.
#else // C++ < C++11
#define BENCHMARK_TEMPLATE(func, arg1)
#endif
#define BENCHMARK_TEMPLATE1(func, arg1)
#define BENCHMARK_TEMPLATE2(func, arg1, arg2)
```
In a multithreaded test, it is guaranteed that none of the threads will start
until all have called KeepRunning, and all will have finished before KeepRunning
returns false. As such, any global setup or teardown you want to do can be
wrapped in a check against the thread index:
```c++
static void BM_MultiThreaded(benchmark::State& state) {
if (state.thread_index == 0) {
// Setup code here.
}
while (state.KeepRunning()) {
// Run the test as normal.
}
if (state.thread_index == 0) {
// Teardown code here.
}
}
BENCHMARK(BM_MultiThreaded)->Threads(2);
To prevent a value or expression from being optimized away by the compiler
the `benchmark::DoNotOptimize(...)` function can be used.
```c++
static void BM_test(benchmark::State& state) {
while (state.KeepRunning()) {
int x = 0;
for (int i=0; i < 64; ++i) {
benchmark::DoNotOptimize(x += i);
}
}
}
```
Output Formats
--------------
The library supports multiple output formats. Use the
`--benchmark_format=<tabular|json>` flag to set the format type. `tabular` is
the default format.
The Tabular format is intended to be a human readable
format. By default the format generates color output. Example tabular output
looks like:
```
Run on (40 X 2801 MHz CPUs)
2015/03/17-18:35:54
Build Type: DEBUG
Benchmark Time(ns) CPU(ns) Iterations
----------------------------------------------------------------------
BM_SetInsert/1024/1 28928 29349 23853 133.097kB/s 33.2742k items/s
BM_SetInsert/1024/8 32065 32913 21375 949.487kB/s 237.372k items/s
BM_SetInsert/1024/10 33157 33648 21431 1.13369MB/s 290.225k items/s
```
The JSON format outputs human readable json split into two top level attributes.
The `context` attribute contains information about the run in general, including
information about the CPU and the date.
The `benchmarks` attribute contains a list of ever benchmark run. Example json
output looks like:
```
{
"context": {
"date": "2015/03/17-18:40:25",
"num_cpus": 40,
"mhz_per_cpu": 2801,
"cpu_scaling_enabled": false,
"build_type": "debug"
},
"benchmarks": [
{
"name": "BM_SetInsert/1024/1",
"iterations": 94877,
"real_time": 29275,
"cpu_time": 29836,
"bytes_per_second": 134066,
"items_per_second": 33516
},
{
"name": "BM_SetInsert/1024/8",
"iterations": 21609,
"real_time": 32317,
"cpu_time": 32429,
"bytes_per_second": 986770,
"items_per_second": 246693
},
{
"name": "BM_SetInsert/1024/10",
"iterations": 21393,
"real_time": 32724,
"cpu_time": 33355,
"bytes_per_second": 1199226,
"items_per_second": 299807
}
]
}
```
Linking against the library
---------------------------
When using gcc, it is necessary to link against pthread to avoid runtime exceptions. This is due to how gcc implements std::thread. See [issue #67](https://github.com/google/benchmark/issues/67) for more details.
没有合适的资源?快使用搜索试试~ 我知道了~
ArduCopter-src-3.4.6.zip_ArduCopter_ArduCopter源码_px4_px4固件3.4.6
共2000个文件
c:3045个
h:2907个
cpp:1275个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 197 浏览量
2022-09-24
10:11:51
上传
评论
收藏 43.67MB ZIP 举报
温馨提示
PX4的ArduCopter-src-3.4.6版本的开源源码
资源推荐
资源详情
资源评论
收起资源包目录
ArduCopter-src-3.4.6.zip_ArduCopter_ArduCopter源码_px4_px4固件3.4.6 (2000个子文件)
nximage_bitmap.c 315KB
stm32_otgfsdev.c 172KB
pic32mx-usbdev.c 137KB
stm32_otgfshost.c 131KB
rtl8187x.c 129KB
ftpd.c 120KB
stm32_usbdev.c 114KB
lpc17_usbdev.c 105KB
mmcsd_sdio.c 104KB
lpc214x_usbdev.c 103KB
stm32_eth.c 103KB
pic32mx-ethernet.c 96KB
libhttpd.c 95KB
kinetis_sdhc.c 92KB
usbmsc_scsi.c 90KB
stm32_sdio.c 90KB
lpc17_sdcard.c 87KB
fs_fat32dirent.c 87KB
lpc43_usb0dev.c 86KB
lpc31_usbdev.c 86KB
lpc17_usbhost.c 85KB
at90usb_usbdev.c 84KB
enc28j60.c 82KB
usbhost_hidkbd.c 79KB
stm32_serial.c 78KB
dm320_usbdev.c 76KB
sam_hsmci.c 76KB
ldnxflat.c 75KB
lpc17_ethernet.c 74KB
pexpr.c 74KB
sdlog2.c 74KB
yconf.c 73KB
nfs_vfsops.c 72KB
cdcacm.c 71KB
pl2303.c 70KB
fs_fat32.c 70KB
ez80_emac.c 69KB
usbhost_storage.c 68KB
kconfig2html.c 68KB
stm32_i2c.c 68KB
smart.c 67KB
up_ili93xx.c 66KB
c5471_ethernet.c 65KB
pblck.c 64KB
pexec.c 63KB
lconf.c 60KB
sensor_params.c 59KB
up_lcd.c 59KB
mmcsd_spi.c 56KB
smartfs_smart.c 56KB
regm_pass2.c 55KB
dm90x0.c 54KB
fs_fat32util.c 54KB
stk500boot.c 53KB
nsh_parse.c 53KB
nxffs_pack.c 52KB
pstm.c 51KB
usbmsc.c 51KB
stm32_spi.c 51KB
stm32_lcd.c 50KB
nxfonts_bitmaps.c 47KB
stm32_can.c 47KB
lpc17_serial.c 47KB
up_touchscreen.c 47KB
lm_ssi.c 47KB
sam_dmac.c 47KB
nrf24l01.c 46KB
stm32_pwm.c 45KB
dm320_framebuffer.c 45KB
sam4l_clockconfig.c 45KB
lpc43_serial.c 44KB
cy_ctest.c 44KB
ssd1289.c 44KB
kinetis_enet.c 44KB
lm_ethernet.c 44KB
lib_libvsprintf.c 44KB
stm32_adc.c 43KB
waypoints.c 43KB
ug-2864hsweg01.c 43KB
tsc2007.c 43KB
up_touchscreen.c 43KB
recvfrom.c 43KB
dhcpd.c 43KB
sst25.c 42KB
lpc43_spifi.c 42KB
lm_serial.c 42KB
AttitudeEKF.c 41KB
talloc.c 41KB
smartfs_utils.c 41KB
w25.c 41KB
ug-2864ambag01.c 41KB
gconf.c 40KB
osmocon.c 40KB
nconf.c 40KB
nxffs_open.c 40KB
up_lcd.c 39KB
up_lcd.c 39KB
kinetis_serial.c 39KB
nokia6100.c 39KB
max11802.c 39KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
JaniceLu
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 1991-2022年上市公司短贷长投短债长用投融资期限错配(包含原始数据及Stata代码).txt
- 5152单片机proteus仿真和源码一个数控直流稳压电源
- 5152单片机proteus仿真和源码一个步进电机的仿真
- unity-webview是Unity 5的一个插件,用于覆盖WebView组件在Unity视图上
- python+sql AI.zip
- 5152单片机proteus仿真和源码一步一步教你51-PC串口通信
- Java毕设之ssm034学生请假系统+jsp.rar
- Java毕设之ssm033单位人事管理系统+jsp.rar
- ESP8266单片机开发5套件
- 5152单片机proteus仿真和源码液晶时钟设计
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功