开发者

Execution time of a file file.txt

开发者 https://www.devze.com 2023-01-21 21:34 出处:网络
I have a file mkList.txt (but my mkList, have 100 lists with 100 numbers) [[22,4,55,7..],[77,3,66,23..],[44,56,23,90..]...]

I have a file mkList.txt (but my mkList, have 100 lists with 100 numbers)

[[22,4,55,7..],[77,3,66,23..],[44,56,23,90..]...]

And

I need to know the time that Erlang uses to read the file list using map/sort and pmap/sort. I did this:

-module(teste).
-export([teste/1]).
-import(lists, [map/2]).
-import(lib_misc, [pmap/2]).

teste(1) -&g开发者_JAVA技巧t;
  {ok, [Data]} = file:consult("mkList1.txt"),
  {Time1, T} = timer:tc(lists, map, [fun lists:sort/1,Data]),
  {Time2, R} = timer:tc(lib_misc, pmap, [fun lists:sort/1,Data]),
  {Time1, T, Time2, R}.

The question is what is wrong in my code, it seems to me that is not calculating the time correctly.

Time 1 = 1
Time 2 = 1.

Could anyone help me? Thanks.


The original solution that you gave is correct. I suspect that you have too little data, so that the result ends up being 1.


This worked for me:

timer:tc(lists, map, [fun (X) -> lists:sort(X) end, Data]).
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号