Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

After seeing Swift's result I had to look into the source to confirm that yes, it was not written by someone who knows the language.

But this is a good benchmark results that demonstrate what performance level can you expect from every language when someone not versed in it does the code porting. Fair play



Author here. There are actually 3 Swift versions in the benchmark:

  - Swift (standard): 893ms
  - Swift (relaxed): 903ms (uses fast-math equivalent)
  - Swift (SIMD): 509ms (explicit SIMD4)
The standard version uses x *= -1.0 which creates a loop-carried dependency that blocks auto-vectorization - same issue as Crystal, Odin, Ada. The SIMD version uses the branchless i & 0x1 trick and is ~1.75x faster.

Fair point that someone versed in Swift would probably use the better pattern in the standard version too. PRs welcome to improve it! The goal was idiomatic-ish code, but I'm not an expert in all 40+ languages.


Even in verbose Java it's barely 20 lines.

Makes the benchmarks game 100 lines seem like major apps.

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...


What do you think they could have done better in the Swift code?


Using overflow operators instead of the ones that check for that each iteration.


Reading https://github.com/niklas-heer/speed-comparison/blob/master/..., I think the only overflow checks could be in

  for i in 2...rounds+2
and I would hope/expect the compiler to be smart enough to know that it only has to check “rounds+2” once there. Swift isn’t exactly new anymore, and it’s supported by a large company.

What do I overlook?


There’s no way overflow checks are responsible for that enormous speed difference from C




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: