测量时间操作的Erlang代码执行? [英] Erlang code to measure time operations took to execute?

查看:361
本文介绍了测量时间操作的Erlang代码执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指点我一些erlang代码,让我花点时间来运行某些代码段需要多长时间?



我没有看到这个可用的erlang库?

解决方案

您可以使用 erlang:statistics 功能。



这是用于Joe Armstrong的编程Erlang书(p141)。



例如

  yourfun() - > 

统计(运行时),
统计(wall_clock),

%你的代码在这里

{_,Time1} = statistics运行时)
{_,Time2} = statistics(wall_clock),
U1 = Time1 * 1000,
U2 = Time2 * 1000,
io:format(Code time = 〜p(〜p)微秒〜n,
[U1,U2])。

在这个例子中 U1 是CPU时间和 U2 是总经过时间(挂钟时间)。


Could somebody be so kind as to point me towards some erlang code which allows me to time how long it takes to run certain pieces of code?

I havent seen an erlang library where this is available?

解决方案

You can use the erlang:statistics function.

This is used in Joe Armstrong's Programming Erlang book (p141).

e.g.

yourfun() ->

    statistics(runtime),
    statistics(wall_clock),

    % your code here

    {_, Time1} = statistics(runtime),
    {_, Time2} = statistics(wall_clock),
    U1 = Time1 * 1000,
    U2 = Time2 * 1000,
    io:format("Code time=~p (~p) microseconds~n",
    [U1,U2]).

In this example U1 is the CPU time and U2 is the total elapsed time (wall clock time).

这篇关于测量时间操作的Erlang代码执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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