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

Sergey Kuratov ksubox.swift at gmail.com
Fri Jan 29 00:30:10 CST 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160129/19539fbd/attachment.html>


More information about the swift-users mailing list