程序执行时间
有没有一个软件/网站可以提交我的 C、C++ 和 Java 代码并获取程序执行时间、使用的内存等统计信息?我有兴趣对不同语言的相同代码进行比较,并估计哪些数据结构/操作更适合哪种语言。
Is there a software/website where I can submit my C, C++ and Java codes and get statistics like the program execution time, memory used ? I'm interested in doing a comparision of the same code in different languages and getting an estimate of which data structures/operations are better suited for which language.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
自己做吧。在 *nix 机器(例如 Linux 和 OSX)上只需从终端运行:
或者
在 Windows 上,您可以 编写一个小批处理脚本来执行相同的操作。
Do it yourself. On a *nix machine (e.g. Linux and OSX) just run from the terminal:
or
On Windows, you can write a little batch script to do the equivalent.
您可以将您的程序粘贴到ideone,它会告诉您执行时间和内存消耗。
You can paste your program at ideone and it will tell you the execution time and memory consumption.
这就是所谓的基准测试,您可以自己做。问题是许多其他变量会影响结果,因此最好控制环境并测量程序的性能,尝试消除尽可能多的外部变量。
例如,建议尽可能在同一机器上、相同环境下对所有程序进行所有测量。
That's called benchmarking and you can do it yourself. The thing is that many other variables affect the results, so it would be best to control the environment and measure the performance of your program trying to eliminate as much external variables as possible.
For example, it is advisable to do all the measurements of all the programs on the same machine, with the same environment, as much as that can be achievable.
如果你想获得功能的基准,使用“时间”是不公平的。您应该用您的语言写下以下内容。
if you want to get benchmark of functions, using "time" is not fair. You should write following in your language.
程序中已使用/空闲内存总量可以在程序中通过java.lang.Runtime.getRuntime()获取;
运行时有几个与内存相关的方法。以下编码示例演示了其用法。
使用 System.currentTimeMillis() 获取开始时间和结束时间并计算差值。
The total used / free memory of an program can be obtained in the program via java.lang.Runtime.getRuntime();
The runtime has several method which relates to the memory. The following coding example demonstrate its usage.
Use System.currentTimeMillis() to get the start time and the end time and calculate the difference.