[swift-users] Huge difference in speed in Array<Class>/Array<Struct> on OSX/Ubuntu platform with same? toolchain

Trent Nadeau tanadeau at gmail.com
Fri Jan 29 13:32:12 CST 2016


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.

On Fri, Jan 29, 2016 at 2:27 PM, Joe Groff via swift-users <
swift-users at swift.org> wrote:

> 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.
>
> -Joe
>
> On Jan 28, 2016, at 10:30 PM, Sergey Kuratov via swift-users <
> swift-users at swift.org> wrote:
>
> Hello,
> 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.
>
> 1. So I have 2 similar computers:
> - Ubuntu 15.10 with clang and Swift-2.2 dev 2016.01.25 for Ubuntu 15.10
> - iMac with OSX 10.11 and  Swift-2.2 dev 2016.01.25 fro OSX (switched to
> this toolchain)
>
> 2. Took extremely simple source code from n-body sample
> <http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&lang=swift&id=3>
>
> 3. Set Release version with -Ounchecked -whole-module-optimization for
> both computers and get results:
>
> Ubuntu - 8.4 sec
> OSX - 167.3 sec
> Was demolished by results
>
> 4. Changed "class Body" to "struct Body" and get another results:
>
> Ubuntu - 12.2 sec
> OSX - 10.0 sec
> Again was deeply moved by results
>
> 5. Added
> *let arrPtr = UnsafeMutablePointer<Body>(bodies)*
> before loops and used arrPtr instead of bodies in loops. Got new result:
>
> For "class Body" variant:
> Ubuntu - 7.3 sec
> OSX - 11.1 sec
>
> For "struct Body" variant:
> Ubuntu - 6.7 sec
> OSX - 8.8 sec
>
> 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 ?
>
> PS: Forgot to say - similar Java program n-body in Java
> <http://benchmarksgame.alioth.debian.org/u64q/program.php?test=nbody&lang=java&id=2>
> takes 6.5 sec on Ubuntu and 9.2 sec on OSX
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>


-- 
Trent Nadeau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160129/ffe3fe03/attachment.html>


More information about the swift-users mailing list