7 ms·
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 benchma
by viktorcode 9mo ago
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
- pizlonator 9mo agoWhat do you think they could have done better in the Swift code?
- viktorcode 9mo agoUsing overflow operators instead of the ones that check for that each iteration.
- Someone 9mo agoReading https://github.com/niklas-heer/speed-comparison/blob/master/src/leibniz.swift 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?
- pizlonator 9mo agoThere’s no way overflow checks are responsible for that enormous speed difference from C
- deleted 9mo ago[deleted]
- igouy 9mo agoEven 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/box-plot-summary-charts.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/comparable.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- nheer 9mo agoAuthor 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.