<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);">><i> -O (Fast) </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>><i> plain for loop with guard </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> Elapsed time: 0.00411999225616455 </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> plain for loop with if </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> Elapsed time: 0.00422400236129761 </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> where test </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> Elapsed time: 0.00419700145721436 </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> eager filter test </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> Elapsed time: 0.033439040184021 </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> lazy filter test </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> Elapsed time: 0.00690501928329468 </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> Program ended with exit code: 0 </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>><i> Code: </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>><i> public func timetest(_ note: String, block: () -> Void) {
</i>><i> let date = NSDate()
</i>><i> block() </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> let timeInterval = NSDate().timeIntervalSince(date) </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> print(note); print("Elapsed time: \(timeInterval)") </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> } </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>><i> let count = 4_000_000
</i>><i> let range = 1...count </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);">><i> </i></span></font></pre><pre><font face="UICTFontTextStyleTallBody"><span style="white-space: normal; background-color: rgba(255, 255, 255, 0);"><i></i>></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... </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); "> mobile)</span></div><div><br>On Jun 14, 2016, at 7:01 AM, Charlie Monroe <<a href="mailto:charlie@charliemonroe.net">charlie@charliemonroe.net</a>> 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 <<a href="mailto:brent@architechies.com">brent@architechies.com</a>> 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>