by ktta · 9y ago · 0 comments
In table 1
Rust Fortran C Go
0m13.660s 0m14.640s 2m32.910s 4m26.240sThey did have a note that C could be faster if language specific features could be used.
Is rust really that performant compared to C? Or did they neglect to even bother checking C's performance?
LBB3_1:
addsd %xmm1, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm0, %xmm2
jae LBB3_1
%xmm0 begins at 0, %xmm1 is 0.04, and %xmm2 is 3.6525E+8.In other words, it's measuring how long it takes to count to 3.6525E+8 by adding 0.04 repeatedly. LLVM (which both Rust and clang use as a backend) optimizes away the actual work of the program.
GCC doesn't seem to optimize things out as aggressively, so that probably explains the difference: https://godbolt.org/g/lBRIIW
Never trust a benchmark you didn't falsify yourself.
printf("x[0][0]=%f\n", x[0][0]);
at the end of main fixes this.Benchmarking is hard.
Also the output is [[NaN, NaN, NaN], [NaN, NaN, NaN]], which is a bit worrying...
Not sure how much this affects the benchmark, but it'd probably be smart to randomise the starting positions.
Clang produces practically the same between the two levels.
On OS X, so can't test if this actually makes a performance difference.
GCC 6.3, -Ofast: 5.93s
GCC 6.3, -O3: 93.06s
GCC 6.3, -O2: 134.43s
Clang 3.9, -O3: 346.92s
Clang 3.9, -Ofast: 5.87s
Intel 15.0, -O3: 110.84s
Intel 15.0, -Ofast: 106.88s
The Intel compiler is relatively old, but mostly it seems to be a case of IEEE 754 conformance -- if enabled, things take longer, if disabled, they’re (probably) as fast in C as in Rust.Rust is able to avoid allocations and de-allocations in many areas where C programmers would manually use alloc and free. I must admit though, that's less relevant to scientific programming, where the heaviest work is mainly matrix matrix multiplication and the sizes of everything is known in advance.
Without reading through the paper, I expect work on the Rust/Fortran side is being vectorized and/or being kept in L1/L2 caches, whereas the C and Go compilers don't use SIMD instructions and/or are generating code that triggers cache misses.
It's not in the general case, but can be for particular code.
Unless the C program was written badly, the fact that Fortran is also faster seems to point to compiler optimizations not easy/possible in C (e.g. involving aliasing assurances).
Which would be the equivalent of writing a comparison between a sledgehammer and jackhammer, without turning the latter on.
https://github.com/marblestation/benchmark-leapfrog
It would be great if somebody have a fresh look at the C version, since I completely agree that it is not normal that its execution time is so far away from Fortran or Rust.
gcc -O3
1m40.302s
gcc -O3 -ffast-math
0m5.110s
rustc -C opt-level=3
0m9.278s
gcc (GCC) 6.3.1 20170109rustc 1.15.1 (021bd294c 2017-02-08)
Edit: Looking into this a bit more, I think 'rustc -C opt-level=3' is optimizing out the actual integration. If I put a println!("{}", x[0][0]) at the end, I end up with 1m43s. Not sure what 'gcc -O3 -ffast-math' is doing; I haven't looked at the disassembly.
Yes, without that it's basically cheating. There is now a GitHub issue: https://github.com/marblestation/benchmark-leapfrog/issues/6
The submitter writes: "final output [for Rust] is 134 seconds, and also the output is [[NaN, NaN, NaN], [NaN, NaN, NaN]] (batman)"
It's surprising that gcc does such a poor job at -O3 though.
http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan... -- in this benchmarks C in most cases faster than Rust, but only in few they have the same performance.
Edit: Looks like using -Ofast instead of -O3 makes a big difference: https://news.ycombinator.com/item?id=13634119
2. How many years already has SIMD not supported on stable been posted as a response in these discussions ?