如何在Haskell中获得程序的运行时间 [英] How to get a program's running time in Haskell

查看:495
本文介绍了如何在Haskell中获得程序的运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过Haskell中的系统时间函数获取程序的运行时间?我想测量整个程序和/或个别函数的执行时间。 解决方案

假设你不只是想要测量程序的总运行时间,如下所示:

  $ time ./A 

然后你可以在Haskell中进行多种计算:



要获得更具统计性的测量结果,请考虑



最后,在所有情况下,您都需要考虑懒惰评估:您是否想要衡量完全评估您生成的任何数据的成本,还是仅仅评估其最外层的构造函数?


How can I go about getting a program's running time through system time functions in Haskell? I would like to measure the execution time of a whole program and/or an individual function.

解决方案

Assuming you don't just want to measure the total running time of your program, like so:

 $ time ./A

Then you can time a computation a number of ways in Haskell:

For more statistically sound measurement, consider

Finally, in all cases, you need to think about lazy evaluation: do you want to measure the cost of fully evaluating whatever data you produce, or just to its outermost constructor?

这篇关于如何在Haskell中获得程序的运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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