-3

While looking for data comparing Rust and C, I went to the benchmarkgame site and tried it myself, and it turned out different from the specified results.(rust vs c clang)

https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust-clang.html

Each source code is as follows, and it was executed through the compile command shown at the bottom of the source code.

The stated result table of "rust vs clang"

However, Rust ran the cargo in the nightly version.

Below is the result of the compiled result measured by time on my pc.

rust vs c clang time checking

The reason for this result is that I compile incorrectly? Or is it normal for these results to come out in the first place?

I am using intel i7 10700k, 16gb ram.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
beginner_
  • 13
  • 4
  • 2
    Please post text as text, not as screenshots. – n. m. could be an AI Nov 12 '21 at 06:50
  • 1
    It's quite hard to follow everything in this question and guess the missing parts. Did you try the rust version with `cargo run` as seems to appear in the screenshot ? If so that's the problem: it's a non optimized build. – Denys Séguret Nov 12 '21 at 06:52
  • Please **search before asking**. The same question is asked again and again and most often the answer is just "compile in release mode". – Denys Séguret Nov 12 '21 at 07:03
  • I'm new to Stack Overflow, so the answer is late. Yes. Thanks to the answer below and your answer, I got the answer. thank you. @DenysSéguret – beginner_ Nov 12 '21 at 07:06
  • With command `time cargo run`, you measure compilation time + execution time of debug build. You should run `cargo build --release` then `time ./target/release/binary_name`. – Angelicos Phosphoros Nov 12 '21 at 09:45
  • @AngelicosPhosphoros Or just `cargo run --release` – user4815162342 Nov 12 '21 at 13:09
  • @user4815162342 No, this would measure time of *compiling* code while we want to measure time to execute compiled code. – Angelicos Phosphoros Nov 12 '21 at 13:32
  • @AngelicosPhosphoros You're right, I missed that `time` was used to measure the run time. The same remark applies to the accepted answer btw. – user4815162342 Nov 12 '21 at 13:34
  • I know! It wasn't a big deal and after the first compilation it seemed that only the runtime time was checked. @AngelicosPhosphoros If there is a problem in the future, I will try again as you told me. Thanks for your help. – beginner_ Nov 15 '21 at 08:53

1 Answers1

3

The screenshot shows that Rust is being compiled in debug mode, which will make for a poor benchmark. Use --release to build it with full optimizations.

time cargo run --release 21

Better yet, use the same build command they did in case the other options are important:

/opt/src/rust-1.55.0/bin/rustc -C opt-level=3 -C target-cpu=ivybridge --C codegen-units=1 -L /opt/src/rust-libs binarytrees.rs -o binarytrees.rust-5.rust_run
user4815162342
  • 141,790
  • 18
  • 296
  • 355
John Kugelman
  • 349,597
  • 67
  • 533
  • 578