正如我在上一个主题中所写:基准代码 - 我做得对吗?我需要找到一种方法来获取基准统计数据,例如平均值、平均值、标准差等。我如何使用我发布的那些方法来做到这一点?请注意,我使用了一种解决方案来对具有时间间隔的代码进行基准测试,而不是通过多次调用函数。有任何想法吗?
我想出了一个,不知道它是否正确(伪代码):
buffsize = 1024;
buffer [buffsize];
totalcycles = 0
// arrays
walltimeresults = []
cputimeresults = []
// benchmarking
for i in (0, iterations):
start = walltime();
fun2measure(args, buffer);
end = walltime();
walltimeresults[i] = end - start;
start = cputime();
fun2measure(args, buffer);
end = cputime();
cputimeresults[i] = end - start;
c1 = cyclecount();
fun2measure(args, buffer);
c2 = cyclecount();
cyclesperbyte = c2-c1/(buffsize);
totalcycles += cyclesperbyte;
for i in range (0, iterations) : sum += walltimeresults[i];
avg_wall_time = sum / iterations;
sum = 0;
for i in range (0, iterations) : sum += cputimeresults[i];
avg_cpu_time = sum / iterations;
avg_cycles = totalcycles / iterations;
这是对的吗?平均值,标准差等怎么样?