Created
December 6, 2018 01:29
-
-
Save taiyow/5aa2343f203287b8ea7d75f029f8ff7c to your computer and use it in GitHub Desktop.
1msのtimerで実質2ms待ちになる調査
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(timer_test). | |
-export([test/2]). | |
test(Wait, Count) -> | |
Begin = erlang:timestamp(), | |
wait_repeat(Wait, Count), | |
End = erlang:timestamp(), | |
DiffUsec = timer:now_diff(End, Begin), | |
DiffSec = DiffUsec / 1000 / 1000, | |
io:format("~p counts in ~p sec, ~p count/sec~n", [Count, DiffSec, Count/DiffSec]). | |
wait_repeat(_Wait, 0) -> | |
ok; | |
wait_repeat(Wait, N) -> | |
timer:sleep(Wait), | |
wait_repeat(Wait, N-1). |
See Measure Elapsed Time at http://erlang.org/doc/apps/erts/time_correction.html#how-to-work-with-the-new-api
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
erl 上で以下で実行。