tags:

views:

56

answers:

2

Hello

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) ->
  {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.

+1  A: 

This worked for me:

timer:tc(lists, map, [fun (X) -> lists:sort(X) end, Data]).
Nathon
I did not understand, who is X?
Gmp
X is the argument to the lambda function.
Nathon
So? 54> {Time1, T} = timer:tc(lists, map, [fun(X) -> lists:sort(X) end, Data]). {1,[[[10,20],[30,2]]]}
Gmp
This works but time is not calculated correctly.
Gmp
Seems right to me. Time is returned in microseconds. `timer:tc(lists, map, [fun (X) -> lists:sort(X) end,26> [lists:seq(1,100000) || _ <- lists:seq(1, 100)]]).` takes 10,067,587 of them for me, which is about 10 seconds, which is about right.
Nathon
Nathon, it seems you're right, I did some tests and see that Erlang is faster by reading the file.Thanks
Gmp
+1  A: 

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

Daniel Luna