<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 29, 2016, at 11:27 AM, Joe Groff via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Arrays of class type have additional overhead on Apple platforms due to the NSArray interoperability. You can use ContiguousArray&lt;Class&gt; if you don't need to interoperate with Objective-C to get more consistent performance.<div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>Using ContiguousArray is a very good idea. You can find other optimization tips and tricks here:</div><div><br class=""></div><div><a href="https://github.com/apple/swift/blob/master/docs/OptimizationTips.rst" class="">https://github.com/apple/swift/blob/master/docs/OptimizationTips.rst</a></div><div><br class=""></div><div>-Nadav</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">-Joe</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 28, 2016, at 10:30 PM, Sergey Kuratov via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello,<div class="">I've just started to work with Swift (have C++ background) and try to make some tests to avoid problems in design. But from beginning I met very disappointing case.</div><div class=""><br class=""></div><div class="">1. So I have 2 similar computers:</div><div class="">- Ubuntu 15.10 with clang and Swift-2.2 dev 2016.01.25 for Ubuntu 15.10</div><div class="">- iMac with OSX 10.11 and &nbsp;Swift-2.2 dev 2016.01.25 fro OSX (switched to this toolchain)</div><div class=""><br class=""></div><div class="">2. Took extremely simple source code from&nbsp;<a href="http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&amp;lang=swift&amp;id=3" target="_blank" class="">n-body sample</a></div><div class=""><br class=""></div><div class="">3. Set Release version with&nbsp;<span style="font-size:1em;white-space:pre-wrap" class="">-Ounchecked -whole-module-optimization for both computers and get results:</span></div><div class=""><span style="font-size:1em;white-space:pre-wrap" class=""><br class=""></span></div><div class=""><span style="font-size:1em;white-space:pre-wrap" class="">Ubuntu - 8.4 sec</span></div><div class=""><span style="font-size:1em;white-space:pre-wrap" class="">OSX - 167.3 sec</span></div><div class=""><span style="white-space:pre-wrap" class="">Was demolished by results</span></div><div class=""><span style="white-space:pre-wrap" class=""><br class=""></span></div><div class=""><span style="white-space:pre-wrap" class="">4. Changed "class Body" to "struct Body" and get another results:</span></div><div class=""><span style="white-space:pre-wrap" class=""><br class=""></span></div><div class=""><span style="white-space:pre-wrap" class="">Ubuntu - 12.2 sec</span></div><div class=""><span style="white-space:pre-wrap" class="">OSX - 10.0 sec</span></div><div class=""><span style="white-space:pre-wrap" class="">Again was deeply moved by results</span></div><div class=""><span style="white-space:pre-wrap" class=""><br class=""></span></div><div class=""><span style="white-space:pre-wrap" class="">5. Added</span></div><div class=""><span style="white-space:pre-wrap" class=""><b class="">let arrPtr = UnsafeMutablePointer&lt;Body&gt;(bodies)</b></span></div><div class=""><span style="white-space:pre-wrap" class="">before loops and used arrPtr instead of bodies in loops. Got new result:</span><br class=""></div><div class=""><span style="white-space:pre-wrap" class=""><br class=""></span></div><div class=""><span style="white-space:pre-wrap" class="">For "class Body" variant:</span></div><div class=""><span style="white-space:pre-wrap" class="">Ubuntu - 7.3 sec</span></div><div class=""><span style="white-space:pre-wrap" class="">OSX - 11.1 sec</span></div><div class=""><span style="white-space:pre-wrap" class=""><br class=""></span></div><div class=""><span style="white-space:pre-wrap" class="">For "struct Body" variant:</span></div><div class=""><span style="white-space:pre-wrap" class="">Ubuntu - 6.7 sec</span></div><div class=""><span style="white-space:pre-wrap" class="">OSX - 8.8 sec</span></div><div class=""><span style="white-space:pre-wrap" class=""><br class=""></span></div><div class=""><span style="white-space:pre-wrap" class="">I believe something wrong with Swift compiler/optimizer if for the same x64 processor same toolchain generate very different code. Especially in 1 case with "class Body" on OSX platform - I guess it's bug. Can somebody comment results ?</span></div><div class=""><span style="white-space:pre-wrap" class=""><br class=""></span></div><div class=""><span style="white-space:pre-wrap" class="">PS: Forgot to say - similar Java program <a href="http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&amp;lang=java&amp;id=2" class="">n-body in Java</a> takes 6.5 sec on Ubuntu and 9.2 sec on OSX</span></div></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>