Skip to content

Commit 84a0574

Browse files
committed
add a PerfUtils.h
1 parent 8d73681 commit 84a0574

File tree

3 files changed

+194
-93
lines changed

3 files changed

+194
-93
lines changed

paddle/math/tests/PerfUtils.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License. */
14+
15+
#pragma once
16+
17+
// Performance Check
18+
#ifdef PADDLE_DISABLE_TIMER
19+
20+
#define EXPRESSION_PERFORMANCE(expression) expression;
21+
22+
#else
23+
24+
#include "paddle/utils/Stat.h"
25+
26+
#define EXPRESSION_PERFORMANCE(expression) \
27+
do { \
28+
char expr[30]; \
29+
strncpy(expr, #expression, 30); \
30+
if (expr[29] != '\0') { \
31+
expr[27] = '.'; \
32+
expr[28] = '.'; \
33+
expr[29] = '\0'; \
34+
} \
35+
expression; \
36+
for (int i = 0; i < 20; i++) { \
37+
REGISTER_TIMER(expr); \
38+
expression; \
39+
} \
40+
LOG(INFO) << std::setiosflags(std::ios::left) << std::setfill(' ') \
41+
<< *globalStat.getStat(expr); \
42+
globalStat.reset(); \
43+
} while (0)
44+
45+
#endif

0 commit comments

Comments
 (0)