Skip to content

Instantly share code, notes, and snippets.

@kunthar
Created October 23, 2014 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunthar/597ae6b7f3264e344703 to your computer and use it in GitHub Desktop.
Save kunthar/597ae6b7f3264e344703 to your computer and use it in GitHub Desktop.
λ kunthar : erl
Erlang/OTP 17 [erts-6.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V6.1 (abort with ^G)
1> inet:get_rc().
[{domain,"kunthar.com"},
{search,["kunthar.com"]},
{resolv_conf,"/etc/resolv.conf"},
{hosts_file,"/etc/hosts"},
{lookup,[native]}]
2> timer:tc(fun() -> inet:gethostbyname("yahoo.com") end).
{97204,
{ok,{hostent,"yahoo.com",[],inet,4,
[{206,190,36,45},{98,139,183,24},{98,138,253,109}]}}}
3> timer:tc(fun() -> inet:gethostbyname("yahoo.com") end).
{650,
{ok,{hostent,"yahoo.com",[],inet,4,
[{206,190,36,45},{98,139,183,24},{98,138,253,109}]}}}
4> inet:get_rc().
[{domain,"kunthar.com"},
{search,["kunthar.com"]},
{resolv_conf,"/etc/resolv.conf"},
{hosts_file,"/etc/hosts"},
{lookup,[native]}]
5> timer:tc(fun() -> inet:gethostbyname("yahoo.com") end).
{461,
{ok,{hostent,"yahoo.com",[],inet,4,
[{206,190,36,45},{98,139,183,24},{98,138,253,109}]}}}
6> S = self().
<0.32.0>
7> R = fun(Y, Acc) -> receive {time, X} -> Y(Y, [X | Acc]) after 5000 -> Acc end end.
#Fun<erl_eval.12.90072148>
8> W = fun(X) -> Itr = lists:seq(1, X), [spawn(fun() -> {T, _} = timer:tc(fun() -> inet:gethostbyname("yahoo.com") end), S ! {time, T} end) || _ <- Itr] end.
#Fun<erl_eval.6.90072148>
9> inet:gethostbyname("yahoo.com").
{ok,{hostent,"yahoo.com",[],inet,4,
[{206,190,36,45},{98,139,183,24},{98,138,253,109}]}}
10> rp(begin spawn(fun() -> W(1000) end), bear:get_statistics(R(R, [])) end).
[{min,32},
{max,3616},
{arithmetic_mean,299.698},
{geometric_mean,233.48311699135945},
{harmonic_mean,178.59062851004614},
{median,275},
{variance,88008.33112712704},
{standard_deviation,296.6619812634019},
{skewness,6.463959997457685},
{kurtosis,56.593976084002286},
{percentile,[{50,275},
{75,363},
{90,466},
{95,561},
{99,1564},
{999,3484}]},
{histogram,[{142,215},
{242,213},
{352,301},
{532,212},
{632,24},
{732,11},
{832,6},
{932,3},
{1032,2},
{1132,0},
{1232,1},
{1332,0},
{1432,1},
{1532,0},
{1632,1},
{1732,0},
{1832,0},
{1932,1},
{2032,1},
{2132,0},
{2232,0},
{2332,1},
{2432,0},
{2532,1},
{2632,1},
{2832,1},
{2932,1},
{3032,0},
{3132,0},
{3232,0},
{4032,3}]},
{n,1000}]
ok
11> rp(begin spawn(fun() -> W(1000) end), bear:get_statistics(R(R, [])) end).
[{min,33},
{max,2181},
{arithmetic_mean,312.32},
{geometric_mean,246.3979302657837},
{harmonic_mean,181.6977331383851},
{median,284},
{variance,50137.276876876866},
{standard_deviation,223.913547774307},
{skewness,2.730521267326848},
{kurtosis,14.640583173605012},
{percentile,[{50,284},
{75,407},
{90,525},
{95,620},
{99,1150},
{999,1994}]},
{histogram,[{113,142},
{193,176},
{273,157},
{353,170},
{433,142},
{533,121},
{633,42},
{733,15},
{833,11},
{933,5},
{1033,4},
{1133,4},
{1233,3},
{1333,1},
{1433,2},
{1533,0},
{1633,0},
{1733,1},
{1833,1},
{1933,1},
{2033,1},
{2133,0},
{2233,1},
{2333,0}]},
{n,1000}]
ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment