From 552d068565172a2b7eaa538cb1c343e098715e4e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 19 Aug 2013 10:16:23 +0000 Subject: Utility benchmarking macros This new macros could be used to benchmark overall execution time of some chunk of code, running in cycle. The usage is: void foo(void) { TIMEIT_BLOCK_INIT(overall_bar); for (...) { ... TIMEIT_BLOCK_BEGIN(over_bar); bar(); TIMEIT_BLOCK_END(oberall_bar); ... } TIMEIT_BLOCK_STATS(overall_bar) } This would print total time which was spent on running function bar(). -- svn merge -r58281:58283 ^/branches/soc-2013-depsgraph_mt --- source/blender/blenlib/PIL_time.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source/blender/blenlib/PIL_time.h') diff --git a/source/blender/blenlib/PIL_time.h b/source/blender/blenlib/PIL_time.h index c3e7e8486d9..3983b5099ff 100644 --- a/source/blender/blenlib/PIL_time.h +++ b/source/blender/blenlib/PIL_time.h @@ -87,6 +87,26 @@ void PIL_sleep_ms(int ms); TIMEIT_END(id); \ } (void)0 +#define TIMEIT_BLOCK_INIT(what) \ + double _timeit_var_##what = 0; \ + (void) 0 + +#define TIMEIT_BLOCK_BEGIN(what) \ + { \ + double _timeit_block_start_##what = PIL_check_seconds_timer(); \ + { (void)0 + +#define TIMEIT_BLOCK_END(what) \ + } \ + _timeit_var_##what += PIL_check_seconds_timer() - _timeit_block_start_##what; \ + } (void)0 + +#define TIMEIT_BLOCK_STATS(what) \ + { \ + printf("%s time (in seconds): %f\n", #what, _timeit_var_##what); \ + fflush(stdout); \ + } (void)0 + #ifdef __cplusplus } #endif -- cgit v1.2.3