<div dir="ltr">I haven't looked at the bridging code yet, but is it possible that the overhead could only be incurred on the first conversion to NSArray? That way if you don't use that functionality it's consistent across platforms, and if you do use it, you get an initial O(n) hit and then O(1) afterwards.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 29, 2016 at 2:27 PM, Joe Groff via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Arrays of class type have additional overhead on Apple platforms due to the NSArray interoperability. You can use ContiguousArray<Class> if you don't need to interoperate with Objective-C to get more consistent performance.<div><br></div><div>-Joe</div><div><br><div><blockquote type="cite"><div><div class="h5"><div>On Jan 28, 2016, at 10:30 PM, Sergey Kuratov via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br></div></div><div><div><div class="h5"><div dir="ltr">Hello,<div>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><br></div><div>1. So I have 2 similar computers:</div><div>- Ubuntu 15.10 with clang and Swift-2.2 dev 2016.01.25 for Ubuntu 15.10</div><div>- iMac with OSX 10.11 and Swift-2.2 dev 2016.01.25 fro OSX (switched to this toolchain)</div><div><br></div><div>2. Took extremely simple source code from <a href="http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&lang=swift&id=3" target="_blank">n-body sample</a></div><div><br></div><div>3. Set Release version with <span style="font-size:1em;white-space:pre-wrap">-Ounchecked -whole-module-optimization for both computers and get results:</span></div><div><span style="font-size:1em;white-space:pre-wrap"><br></span></div><div><span style="font-size:1em;white-space:pre-wrap">Ubuntu - 8.4 sec</span></div><div><span style="font-size:1em;white-space:pre-wrap">OSX - 167.3 sec</span></div><div><span style="white-space:pre-wrap">Was demolished by results</span></div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">4. Changed "class Body" to "struct Body" and get another results:</span></div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">Ubuntu - 12.2 sec</span></div><div><span style="white-space:pre-wrap">OSX - 10.0 sec</span></div><div><span style="white-space:pre-wrap">Again was deeply moved by results</span></div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">5. Added</span></div><div><span style="white-space:pre-wrap"><b>let arrPtr = UnsafeMutablePointer<Body>(bodies)</b></span></div><div><span style="white-space:pre-wrap">before loops and used arrPtr instead of bodies in loops. Got new result:</span><br></div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">For "class Body" variant:</span></div><div><span style="white-space:pre-wrap">Ubuntu - 7.3 sec</span></div><div><span style="white-space:pre-wrap">OSX - 11.1 sec</span></div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">For "struct Body" variant:</span></div><div><span style="white-space:pre-wrap">Ubuntu - 6.7 sec</span></div><div><span style="white-space:pre-wrap">OSX - 8.8 sec</span></div><div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">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><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">PS: Forgot to say - similar Java program <a href="http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&lang=java&id=2" target="_blank">n-body in Java</a> takes 6.5 sec on Ubuntu and 9.2 sec on OSX</span></div></div></div></div>
_______________________________________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div><br>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Trent Nadeau</div>
</div>