<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> -O (Fast)&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i>&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>&gt;<i> plain for loop with guard&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> Elapsed time: 0.00411999225616455&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> plain for loop with if&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> Elapsed time: 0.00422400236129761&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> where test&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> Elapsed time: 0.00419700145721436&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> eager filter test&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> Elapsed time: 0.033439040184021&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> lazy filter test&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> Elapsed time: 0.00690501928329468&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> Program ended with exit code: 0&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i>&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>&gt;<i> Code:&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i>&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>&gt;<i> public func timetest(_ note: String, block: () -&gt; Void) {
</i>&gt;<i>     let date = NSDate()
</i>&gt;<i>     block()&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i>     let timeInterval = NSDate().timeIntervalSince(date)&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i>     print(note); print("Elapsed time: \(timeInterval)")&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i> }&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i>&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>&gt;<i> let count = 4_000_000
</i>&gt;<i> let range = 1...count&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">&gt;<i>&nbsp;</i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>&gt;</span></font><i><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"> timetest("plain for loop with guard") {</span></font><span style="-webkit-text-size-adjust: auto; background-color: rgb(255, 255, 255);">
</span></i></pre><div><i>So this is what we are taking about...&nbsp;</i></div><div><br></div><br><div>Regards</div>(From<span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">&nbsp;mobile)</span></div><div><br>On Jun 14, 2016, at 7:01 AM, Charlie Monroe &lt;<a href="mailto:charlie@charliemonroe.net">charlie@charliemonroe.net</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><span></span><br><blockquote type="cite"><span>On Jun 13, 2016, at 9:59 PM, Brent Royal-Gordon &lt;<a href="mailto:brent@architechies.com">brent@architechies.com</a>&gt; wrote:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>See the benchmarks me and Erica have posted here a few days back - even with the lazy accessor, if you decided to use filter(_:), you lost 10+% of performance. Correct way to do this without `where` and without performance penalization is to use guard within the for-in loop.</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>10% on a microbenchmark repeater 4000000 times is hardly a justification for going on way or the other.</span><br></blockquote></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>You're right: 10% on a microbenchmark isn't the best possible data. If you have better data, we are all ears.</span><br></blockquote><span></span><br><span>I never said that it's a deal-breaker, but it is definitely something to consider. Since we're discussing performance of the loop itself, you can't perform much in the body of the for loop since it would skew the result (obviously). </span><br></div></blockquote><div><br></div><div>I used to do low latency java for trading systems... the kind of coding where we would go out of our way to avoid ANY intraday gc activity (yes it can be done, even for parsing xml files). So we cared about a lot of things... But when you look at the numbers above on a 4_000_000 iterations loop and say the differential matters? I say you are probably using the wrong tools to write your code in the first place, and you should be using accelerate.</div><div><br></div><div>As for the '</div><br><blockquote type="cite"><div><span></span><br><span>I've previously noted that if/guard-continue come in really close speed-wise, which makes them candidates for a fix-it in case `where` is indeed removed.</span><br><span></span><br><span>My response here was solely to Jean-Daniel's note that he mustn't forget to include the lazy accessor, pointing out that even the lazy accessor is slower than using an inline check.</span><br><span></span><br><span></span><br><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>-- </span><br></blockquote><blockquote type="cite"><span>Brent Royal-Gordon</span><br></blockquote><blockquote type="cite"><span>Architechies</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><span></span><br></div></blockquote></body></html>