<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:blue;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>On 3/16, Hynek Vychodil wrote:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>Are you sure that there is big difference between
compute X-T and decide X<T or which one is less expensive? I'm not! If you
haven't measured ...<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>For what it’s worth, I timed them,
and ROK’s is about 40–50% faster. That being said, my
question was related more to whether I was lacking in my
documentation-searching abilities rather than to any difficulty in writing a
floor function. However, as an Erlang hobbyist, I enjoyed the exercise in
timing, and completely overengineered my test harness for your pleasure.
Here’s my code, in case you spot some error and so want to appeal my
conclusions:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<div style='mso-element:para-border-div;border:solid windowtext 1.0pt;
padding:1.0pt 4.0pt 1.0pt 4.0pt;margin-left:.5in;margin-right:0in'>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>>
floor:test(10000000).<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>[{ippolito,[{runtime,17766},<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
{wall_clock,17782},<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
{runtime_speed_vs_okeefe,0.6877181132500282}]},<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'> {okeefe,[{runtime,12218},<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
{wall_clock,12218},<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
{runtime_speed_vs_ippolito,1.454084138156818}]}]<o:p></o:p></span></font></p>
</div>
<p class=MsoNormal style='margin-left:.5in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<div style='mso-element:para-border-div;border:solid windowtext 1.0pt;
padding:1.0pt 1.0pt 1.0pt 1.0pt;margin-left:.5in;margin-right:0in'>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>-module(floor).<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>-export([ippolito/1,
okeefe/1]).<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>-spec
ippolito(float()) -> integer().<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>-spec
okeefe (float()) -> integer().<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>-export([test/1]).<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>-spec
test(non_neg_integer()) -> term().<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>ippolito(X)
-><o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
T = trunc(X),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
case (X - T) of<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
Neg when Neg < 0 -> T - 1;<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
Pos when Pos > 0 -> T;<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
_ -> T<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
end.<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>okeefe(X)
-><o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
T = trunc(X),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
if X < T -> T - 1<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
; true -> T<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
end.<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>test(N)
-><o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
Tests = [{ippolito, fun ippolito/1}, {okeefe, fun okeefe/1}],<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
Results = [ {Name, test(F, N)} || {Name, F} <- Tests ],<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
_Report = lists:map(add_comparisons_to_others(Results), Results).<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>test(F,
N) -><o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
Args = [-4.0, -2.75, -1.5, -0.1, 0.0, 1.1, 2.5, 3.75, 4.0],<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
% Check to make sure results are accurate<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
ResultsAreAccurate = lists:seq(-4, 4) == [F(X) || X <- Args],<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
if ResultsAreAccurate -> ok end,<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
Fun = fun() -> lists:foreach(F, Args) end,<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
statistics(runtime),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
statistics(wall_clock),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
repeat(N, Fun),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
{_, RunTime} = statistics(runtime),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
{_, WallClockTime} = statistics(wall_clock),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
[ {runtime, RunTime}, {wall_clock, WallClockTime}].<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>repeat(0,
_F) -> ok;<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>repeat(N,
F) -> F(), repeat(N - 1, F).<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>filter_out(Name)
-><o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
fun<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
({OtherName, _}) when OtherName == Name -> false;<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
(_) -> true<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
end.<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>filter_out(Name,
List) -> lists:filter(filter_out(Name), List).<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>add_comparisons_to_others(FullResults)
-><o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
fun({Name, Stats}) -><o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
Others = filter_out(Name, FullResults),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
RunTime = proplists:get_value(runtime, Stats),<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
Comparisons =<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
[ {list_to_atom("runtime_speed_vs_" ++ atom_to_list(OtherName)),
SpeedComparison}<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
|| {OtherName, OtherStats} <- Others<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
, OtherRunTime <- [proplists:get_value(runtime, OtherStats)]<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
, SpeedComparison <- [OtherRunTime / RunTime]<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
],<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
{Name, Stats ++ Comparisons}<o:p></o:p></span></font></p>
<p class=MsoNormal style='border:none;padding:0in'><font size=1 color=navy
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:navy'>
end.<o:p></o:p></span></font></p>
</div>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Cheers,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>David<o:p></o:p></span></font></p>
</div>
</body>
</html>