Which format should I use to convert microseconds into seconds?

161 views
Skip to first unread message

Gilmara Pompelli

unread,
Nov 5, 2010, 11:13:43 AM11/5/10
to erlang-prog...@googlegroups.com, erla...@googlegroups.com
-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}.


Which format should I use to convert microseconds into seconds?

{Time1, T/1000000}

Return
1.0e-6


Thanks

Reza Moussavi

unread,
Nov 10, 2010, 7:30:21 PM11/10/10
to Erlang Programming
1.0e-6 = 0.000001 , so maybe it would be better to use milliseconds
for this small numbers or use a function like this:

Nano=fun(A) when A>1.0e+6 -> {trunc(A/1.0e6),sec}; (A) when A>1000 ->
{trunc(A/1000),milliSec}; (A)-> {A,nanoSec} end.

sample run:

> Nano(12).
{12,nanoSec}
> Nano(56780).
{56,milliSec}
> Nano(15678000).
{15,sec}


On Nov 5, 4:13 pm, Gilmara Pompelli <gilmarampompe...@gmail.com>
wrote:

Gilmara Pompelli

unread,
Nov 11, 2010, 4:25:24 PM11/11/10
to erlang-prog...@googlegroups.com
When I put in my program the following error appeared:

./cenapad.erl:53: syntax error before: Nano

Thanks

2010/11/10 Reza Moussavi <reza.m...@gmail.com>:

> --
> Erlang Programming Website:
> http://www.erlangprogramming.org/

--
Tenha um melhor amigo.Preserve seu direito a vida. Isso é lei.

Art. 2º - Aquele que, em lugar público ou privado, aplicar ou fizer
aplicar maus tratos aos animais, incorrerá em multa de Cr$.. e na pena
de prisão celular de 2 a 15 dias, quer o delinqüente seja ou não o
respectivo proprietário, sem prejuízo da ação civil que possa caber.
Decreto Lei nº 24645/34.

Visite:

www.ufpe.br/adoteumviralata

Reza Moussavi

unread,
Nov 11, 2010, 6:41:46 PM11/11/10
to Erlang Programming
Let me see the whole function you use, may some minor syntax error
there is.

On Nov 11, 10:25 pm, Gilmara Pompelli <gilmarampompe...@gmail.com>
wrote:
> When I put in my program the following error appeared:
>
> ./cenapad.erl:53: syntax error before: Nano
>
> Thanks
>
> 2010/11/10 Reza Moussavi <reza.muss...@gmail.com>:

Gilmara Pompelli

unread,
Nov 12, 2010, 6:42:04 AM11/12/10
to erlang-prog...@googlegroups.com
I think I'm calling the function incorrectly. I made some other forms
but could not.


-module(teste).
-export([tests/1, fib/1]).


-import(lists, [map/2]).
-import(lib_misc, [pmap/2]).

%% A função tests ([N]), será a função usada como parãmetro, onde N é
o número de shedulers (número de processadores)
tests([N]) ->
Nsched = list_to_integer(atom_to_list(N)),
run_tests(1, Nsched).

%% run_tests é a função de retorno
run_tests(N, Nsched) ->
case test(N) of
stop ->
ok;
Val ->
io:format("~p.~n ",[{Nsched, Val}]),
run_tests(N+1, Nsched)
end.


%% Esta função irá gerar uma sequência de 100 listas cada uma contendo
100 números inteiros randômicos e calcula o tempo de execução de um
sort usando map e em seguida pmap
test(1) ->
{ok, [L]} = file:consult("mkList1.txt"),
{Time2, S2} = timer:tc(lib_misc, pmap, [fun(X) -> lists:sort(X) end, L]),
{sort, Time2};

%% Aqui é gerada uma lista de 100 elementos número 27 “L =
[27,27,27,..]” utilizada para calcular os números de fibonacci
calculando também o tempo utilizado usando map e pmap.
test(2) ->
L = lists:duplicate(100, 27),
{Time2, S2} = timer:tc(lib_misc, pmap, [fun ptests:fib/1, L]),
{fib, Time2};
test(3) ->
stop.


%% Cálculo dos numerous de fibonacci
fib(0) -> 1;
fib(1) -> 1;
fib(N) -> fib(N-1) + fib(N-2).


Nano = fun (A) when A > 1.0e+6 -> {trunc(A / 1.0e6),sec};


(A) when A > 1000 -> {trunc(A / 1000),milliSec};
(A) -> {A,nanoSec} end.

Thanks

2010/11/11 Reza Moussavi <reza.m...@gmail.com>:

Reza Moussavi

unread,
Nov 13, 2010, 11:14:50 AM11/13/10
to Erlang Programming
in a wrong way u put the Nano fun.
if u want u can use function instead of fun
so you can write the following function

Nano(A) when A > 1.0e+6 -> {trunc(A / 1.0e6),sec};
Nano(A) when A > 1000 -> {trunc(A / 1000),milliSec};
Nano(A) -> {A,nanoSec}.

then in the lines that u use time to show u can change like this;
instead of (for example) {fib,Time2} u can use {fib,Nano(Time2)}

Good Luck

On Nov 12, 12:42 pm, Gilmara Pompelli <gilmarampompe...@gmail.com>
wrote:
> 2010/11/11 Reza Moussavi <reza.muss...@gmail.com>:

Hynek Vychodil

unread,
Nov 13, 2010, 12:20:22 PM11/13/10
to erlang-prog...@googlegroups.com
On Sat, Nov 13, 2010 at 5:14 PM, Reza Moussavi <reza.m...@gmail.com> wrote:
> in a wrong way u put the Nano fun.
> if u want u can use function instead of fun
> so you can write the following function
>
> Nano(A)  when A > 1.0e+6 -> {trunc(A / 1.0e6),sec};
> Nano(A) when A > 1000 -> {trunc(A / 1000),milliSec};
> Nano(A) -> {A,nanoSec}.

Function name have to start with lower case of course.

--
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com

Reza Moussavi

unread,
Nov 14, 2010, 8:02:29 PM11/14/10
to Erlang Programming
thanks Hynek
happens while copy/paste Nano=fun(..)... and change to function :-p


On Nov 13, 6:20 pm, Hynek Vychodil <vychodil.hy...@gmail.com> wrote:

Gilmara Pompelli

unread,
Nov 16, 2010, 12:10:33 PM11/16/10
to erlang-prog...@googlegroups.com
Our I was in a hurry and did not even realize it.

Thanks for the help.

Gilmara

2010/11/14 Reza Moussavi <reza.m...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages