Skip to content

Instantly share code, notes, and snippets.

@manuel-rubio
Created April 3, 2013 15:42
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save manuel-rubio/5302361 to your computer and use it in GitHub Desktop.
#!/usr/bin/env escript
epoch() ->
{Mega,Sec,Mili} = now(),
(Mega * 1000000) + Sec + (Mili / 1000000).
measure(F) ->
Ini = epoch(),
F(),
epoch() - Ini.
main(_Args) ->
Times = lists:seq(1,1000000),
Test1 = fun() -> [ os:timestamp() || _ <- Times ] end,
Test2 = fun() -> [ now() || _ <- Times ] end,
io:format("os:timestamp = ~5.2f ~5.2f ~5.2f~n", [
measure(Test1), measure(Test1), measure(Test1)
]),
io:format("erlang:now = ~5.2f ~5.2f ~5.2f~n", [
measure(Test2), measure(Test2), measure(Test2)
]),
0.
@manuel-rubio
Copy link
Author

In this case erlang:now() is fater than os:timestamp(), but if we try in a concurrent fashion:

https://gist.github.com/manuel-rubio/5303075

The results are the opposite.

@manuel-rubio
Copy link
Author

Adding the:

-mode(compile).

As in this fork: https://gist.github.com/legoscia/5303050

The results are very different. The better results are os:timestamp().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment