Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimise for size when compiling rust #28

Closed
tomcraven opened this issue Sep 28, 2018 · 10 comments
Closed

optimise for size when compiling rust #28

tomcraven opened this issue Sep 28, 2018 · 10 comments

Comments

@tomcraven
Copy link

optimising for size with rust produces a significant difference, comparable to nim on my machine

$ rustc -O fib.rs && hyperfine ./fib
Benchmark #1: ./fib
  Time (mean ± σ):      6.878 s ±  0.036 s    [User: 6.862 s, System: 0.009 s]
  Range (min … max):    6.822 s …  6.948 s
$ rustc -C opt-level=s fib.rs && hyperfine ./fib
Benchmark #1: ./fib
  Time (mean ± σ):      5.334 s ±  0.035 s    [User: 5.320 s, System: 0.006 s]
  Range (min … max):    5.284 s …  5.386 s
$ nim cpp -d:release fib.nim && hyperfine ./fib
Hint: used config file '/<redacted>/.choosenim/toolchains/nim-0.19.0/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: fib [Processing]
Hint:  [Link]
Hint: operation successful (12272 lines compiled; 0.214 sec total; 13.191MiB peakmem; Release Build) [SuccessX]
Benchmark #1: ./fib
  Time (mean ± σ):      5.338 s ±  0.030 s    [User: 5.324 s, System: 0.007 s]
  Range (min … max):    5.286 s …  5.385 s
@CryZe
Copy link

CryZe commented Sep 28, 2018

The ASM between both opt-level=s and opt-level=3 (or 2) is exactly the same, so I'm not entirely sure where these performance differences come from

@CryZe
Copy link

CryZe commented Sep 28, 2018

Here's the comparison: https://godbolt.org/z/d6504t

@drujensen
Copy link
Owner

Let me know if this is a normal flag for Rust. I am ok with changing it. It shaved ~ 0.5s from the results on my machine. 5.817 vs 6.438

@CryZe
Copy link

CryZe commented Oct 2, 2018

Yeah they stabilized this flag a few releases ago. You can integrate it if you want.

@xeoneux
Copy link

xeoneux commented Oct 3, 2018

Same for me 😄

@drujensen
Copy link
Owner

done. Although I think the upgrade to Mojave had an affect on the results. I plan on moving this to linux soon.

@tomcraven
Copy link
Author

8e64856

The time for the rust version increased?

@drujensen
Copy link
Owner

yes. Crystal slowed by a whole second as well. not sure the cause. LLVM?

@drujensen
Copy link
Owner

maybe i should change it back?

$rustc -O fib.rs
drujensen:~/workspace/crystal/fib (master)
$time ./fib
2971215073

real	0m6.363s
user	0m6.352s
sys	0m0.006s
drujensen:~/workspace/crystal/fib (master)
$rustc -C opt-level=s fib.rs
drujensen:~/workspace/crystal/fib (master)
$time ./fib
2971215073

real	0m6.980s
user	0m6.970s
sys	0m0.006s

@tommket
Copy link

tommket commented Mar 13, 2019

Why not use opt-level=3 for speed optimization? It makes more sense when trying to benchmark for speed.
On my machine it was with:
stable-x86_64-unknown-linux-gnu updated - rustc 1.33.0 (2aa4c46cf 2019-02-28)
opt-level=s - around 6.0 +- 0.1 seconds
opt-level=3 - around 5.0 +- 0.1 seconds
As I just checked on godbolt the resulting assemblies are different: godbolt comparison of opt-level=s and opt-level=3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants