正如我在上一个主题中所写:基准测试代码-我做得对吗?我需要找到一种方法来获得基准统计数据,比如平均值、平均值、标准差等。我如何使用我发布的方法来做到这一点?请注意,我使用了一个解决方案来对代码进行时间间隔基准测试,而不是多次调用函数。有什么想法吗?
我只想出了一个,不知道它是否正确(伪代码):
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;
这是正确的吗?平均值、标准差等如何?
您的平均值看起来不错。
平均值(即平均值)为
mean = 1/N * sum( x[i] )
标准差是方差的平方根:
sigma = sqrt( 1/N * sum( (x[i]-mean)^2 )