Haskell测量功能性能 [英] Haskell measuring function performance

查看:145
本文介绍了Haskell测量功能性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Haskell中,我如何简单地测量函数性能。例如,运行需要多长时间,或需要多少内存?我知道分析,但是,有没有更简单的方法,不需要我更改我的代码太多?

解决方案

测量运行需要多长时间,需要多少内存是两个独立的问题,即:基准测试和性能分析。 Haskell为这两个工具都有一套明确的工具。解决这两个问题都不需要对实际应用程序的代码进行任何更改。



标杆管理



这是使用库完成。尼克拉斯在评论中提出了这方面的最终胜利者,即 Criterion < STRONG> 。该图书馆设计得非常好,不难使用,并生成一个非常详细的数据



工作流程如下:创建一个单独的模块,其中包含基准的设置,编译并使用选项运行。要获得可用选项的参考,请使用 --help 修饰符运行它。

您可以找到设置模块的示例这里



分析



已经有足够的优质材料,所以我我们只需要引用他们:


In Haskell, how can i 'simply' measure a functions performance. For example, how long it takes to run, or how much memory it takes?. I am aware of profiling, however, is there a more simple way that will not require me to change my code too much?

解决方案

Measuring how long it takes to run and how much memory it takes are two separate problems, namely: benchmarking and profiling. Haskell has a well defined set of tools for both. Solving neither of the problems requires you to make any changes to the actual application's code.

Benchmarking

This is done using libraries. There is an ultimate winner in that area, which was suggested by Niklas in the comments, namely Criterion. The library is very well designed, isn't hard to use and produces a very detailed data.

The workflow is the following: you create a separate module containing the setup of your benchmark, compile it and run it with options. To get a reference on available options run it with --help modifier.

You can find examples of setup modules here.

Profiling

There is enough of good materials on that already, so I'll just refer to them:

这篇关于Haskell测量功能性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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