是否有基准数的更好的方式比定时C程序? [英] Is there a better way to benchmark a C program than timing?

查看:120
本文介绍了是否有基准数的更好的方式比定时C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编码有排序大阵(可达400万文本字符串)一个小程序。好像我做得不错吧,因为基数排序和归并的组合已经切原Q(uick)排序执行时间不到一半。

I'm coding a little program that has to sort a large array (up to 4 million text strings). Seems like I'm doing quite well at it, since a combination of radixsort and mergesort already cut the original q(uick)sort execution time in less than half.

执行时间是主要的一点,因为这是我用什么的基准的我的一片code的。

Execution time being the main point, since this is what I'm using to benchmark my piece of code.

我的问题是:

有没有更好的(即更可靠)基准测试程序不仅仅是时间的执行方式?它有点儿工作,但相同的程序(使用相同的后台进程运行),如果运行两次,通常有稍微不同的执行时间。

Is there a better (i. e. more reliable) way of benchmarking a program than just time the execution? It kinda works, but the same program (with the same background processes running) usually has slightly different execution times if run twice.

这有点违背了检测小的改进的目的。和几个小的改进可以添加到一个大的...

This kinda defeats the purpose of detecting small improvements. And several small improvements could add up to a big one...

预先感谢任何输入!

结果:

我设法gprof的在Windows下工作(使用gcc和MinGW)。相比,我的正常的编译器(TCC)GCC行为会很差(考虑执行时间),但它给了我不少的见解。

I managed to get gprof to work under Windows (using gcc and MinGW). gcc behaves poorly (considering execution time) compared to my normal compiler (tcc), but it gave me quite some insight.

推荐答案

尝试分析工具,这也将告诉你该程序将时间花在。 gprof的 是经典的C评测工具,至少在Unix上。

Try a profiling tool, that will also show you where the program is spending its time. gprof is the classic C profiling tool, at least on Unix.

这篇关于是否有基准数的更好的方式比定时C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆