Is it a way to create a clever macro to automatically benchmark something in C?

别等时光非礼了梦想. 提交于 2019-12-06 04:41:08

You can just pass the whole function call, including parameters, and ignore any function result, e.g.

#define BENCH(process, bench_struct, description)      \
  int i;                                               \
  bench_struct.description = description;              \
  bench_struct.nbenchs = 50;                           \
  double start = get_time();                           \
  for (i = 0; i < bench_struct.nbenchs; ++i)           \
    process;                                           \
  bench_struct.times = get_time() - start;

BENCH(func(x, y, z), func_bench, func_description)

(Note the small change to the macro - the parentheses have been removed from process.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!