Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
e6ea02c2
Mace
项目概览
Xiaomi
/
Mace
通知
106
Star
40
Fork
27
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e6ea02c2
编写于
9月 01, 2017
作者:
W
wuchenghui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add a test benchmark example
上级
bb10fdac
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
13 deletion
+42
-13
mace/core/testing/test_benchmark.cc
mace/core/testing/test_benchmark.cc
+22
-11
mace/core/testing/test_benchmark.h
mace/core/testing/test_benchmark.h
+2
-2
mace/examples/benchmark_example.cc
mace/examples/benchmark_example.cc
+18
-0
未找到文件。
mace/core/testing/test_benchmark.cc
浏览文件 @
e6ea02c2
...
...
@@ -37,6 +37,18 @@ Benchmark::Benchmark(const char* name, void (*fn)(int, int, int))
Register
();
}
Benchmark
*
Benchmark
::
Arg
(
int
x
)
{
CHECK
(
num_args_
==
1
);
args_
.
push_back
(
std
::
make_pair
(
x
,
-
1
));
return
this
;
}
Benchmark
*
Benchmark
::
ArgPair
(
int
x
,
int
y
)
{
CHECK
(
num_args_
==
2
);
args_
.
push_back
(
std
::
make_pair
(
x
,
y
));
return
this
;
}
// Run all benchmarks
void
Benchmark
::
Run
()
{
...
...
@@ -44,32 +56,31 @@ void Benchmark::Run() {
// Compute name width.
int
width
=
10
;
string
name
;
char
name
[
100
]
;
for
(
auto
b
:
*
all_benchmarks
)
{
name
=
b
->
name_
;
for
(
auto
arg
:
b
->
args_
)
{
name
.
resize
(
b
->
name_
.
size
());
strcpy
(
name
,
b
->
name_
.
c_str
());
if
(
arg
.
first
>=
0
)
{
name
+=
"/"
+
arg
.
first
;
sprintf
(
name
,
"%s/%d"
,
name
,
arg
.
first
)
;
if
(
arg
.
second
>=
0
)
{
name
+=
"/"
+
arg
.
second
;
sprintf
(
name
,
"%s/%d"
,
name
,
arg
.
second
)
;
}
}
width
=
std
::
max
<
int
>
(
width
,
name
.
size
(
));
width
=
std
::
max
<
int
>
(
width
,
strlen
(
name
));
}
}
printf
(
"%-*s %10s %10s
\n
"
,
width
,
"Benchmark"
,
"Time(ns)"
,
"Iterations"
);
printf
(
"%s
\n
"
,
string
(
width
+
22
,
'-'
).
c_str
());
for
(
auto
b
:
*
all_benchmarks
)
{
name
=
b
->
name_
;
for
(
auto
arg
:
b
->
args_
)
{
name
.
resize
(
b
->
name_
.
size
());
strcpy
(
name
,
b
->
name_
.
c_str
());
if
(
arg
.
first
>=
0
)
{
name
+=
"/"
+
arg
.
first
;
sprintf
(
name
,
"%s/%d"
,
name
,
arg
.
first
)
;
if
(
arg
.
second
>=
0
)
{
name
+=
"/"
+
arg
.
second
;
sprintf
(
name
,
"%s/%d"
,
name
,
arg
.
second
)
;
}
}
...
...
@@ -89,7 +100,7 @@ void Benchmark::Run() {
(
items_processed
*
1e-6
)
/
seconds
);
full_label
+=
buf
;
}
printf
(
"%-*s %10.0f %10d
\t
%s
\n
"
,
width
,
name
.
c_str
()
,
printf
(
"%-*s %10.0f %10d
\t
%s
\n
"
,
width
,
name
,
seconds
*
1e9
/
iters
,
iters
,
full_label
.
c_str
());
}
}
...
...
mace/core/testing/test_benchmark.h
浏览文件 @
e6ea02c2
...
...
@@ -24,6 +24,8 @@ class Benchmark {
Benchmark
(
const
char
*
name
,
void
(
*
fn
)(
int
));
Benchmark
(
const
char
*
name
,
void
(
*
fn
)(
int
,
int
));
Benchmark
(
const
char
*
name
,
void
(
*
fn
)(
int
,
int
,
int
));
Benchmark
*
Arg
(
int
x
);
Benchmark
*
ArgPair
(
int
x
,
int
y
);
static
void
Run
();
...
...
@@ -40,12 +42,10 @@ class Benchmark {
};
void
RunBenchmarks
();
void
SetLabel
(
const
std
::
string
&
label
);
void
BytesProcessed
(
int64
);
void
ItemsProcessed
(
int64
);
void
StartTiming
();
void
StopTiming
();
void
UseRealTime
();
}
// namespace testing
}
// namespace mace
...
...
mace/examples/benchmark_example.cc
浏览文件 @
e6ea02c2
...
...
@@ -25,3 +25,21 @@ static void foo(int iters) {
BENCHMARK
(
foo
);
static
void
bar
(
int
iters
,
int
n
)
{
const
int64
tot
=
static_cast
<
int64
>
(
iters
)
*
n
;
mace
::
testing
::
ItemsProcessed
(
tot
);
mace
::
testing
::
BytesProcessed
(
tot
*
(
sizeof
(
float
)));
float
*
inp
=
new
float
[
n
];
float
*
out
=
new
float
[
n
];
while
(
iters
--
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
out
[
i
]
=
inp
[
i
]
*
2.0
;
}
}
delete
[]
inp
;
delete
[]
out
;
}
BENCHMARK
(
bar
)
->
Arg
(
32
)
->
Arg
(
64
)
->
Arg
(
128
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录