Skip to content

Instantly share code, notes, and snippets.

@amtal
Created May 20, 2011 00:55
Show Gist options
  • Save amtal/982122 to your computer and use it in GitHub Desktop.
Save amtal/982122 to your computer and use it in GitHub Desktop.
Playing with now()'s clock skew effect at high call rates.
-module(now_skew).
-compile(export_all).
go() ->
A = os:timestamp(),
NA = now(),
Master = self(),
spawn(fun()->loop(1000000), Master!done end),
%spawn(fun()->loop(500000), Master!done end),
receive done->ok end,
%receive done->ok end,
B = os:timestamp(),
NB = now(),
DeltaNow = timer:now_diff(NB,NA),
DeltaOS = timer:now_diff(B,A),
[{now,DeltaNow}, {os,DeltaOS}, {diff,DeltaNow-DeltaOS}
,{skew,DeltaNow/DeltaOS}].
loop(0) -> done;
loop(N) -> now(), loop(N-1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment