M:N Threading, C, Rust and Java?



My interest in Rust is (so far) mainly with threading - I found this:

  • which was interesting but I couldn’t do the compile with gcc on Fedora 22 x86_64 but I got this from the Rust test:

Rust Results: 45,699,455 shorts per second.

  • which just shows I have a slow (four core) processor I guess . .

Then when I was looking for info on M:N Threading I found this:


and with some updating of the Rust code to this:

use std::thread;

fn main() {
for _ in 0…100_000 {
let cur = thread::spawn(move||

I was able to do the C : Rust comparison and I got:


real 0m1.464s
user 0m0.383s
sys 0m2.490s


real 0m3.190s
user 0m1.506s
sys 0m4.503s

Do people think this is a reasonable and fair comparison of C and Rust threading?

Is there a Java Guru here who could produce the equivalent Java program for me?




Note the date in that URL: 2013-November. That’s a very, very long time ago in Rust time. N:M threading is entirely gone now.

How did you write the C code? Did you compile the Rust code with optimizations?



Yes, I forgot to mention it was an old test . . I did see some comments about M:N being likely to be removed - is there a link to quick summary anywhere?

I compiled the C code as is from the link. No Rust opts - just “rustc t103.rs” . .



Try compiling both with optimizations enabled.

gcc -O3 t103.c (or -O2)
rustc -C opt-level=3 t103.rs

On my machine, the C version is still faster. However, it’s taking significantly less system time (which shouldn’t be lanaguage dependent unless the rust standard library is making twice as many expensive system calls) and appears to be segfaulting every few runs so something is a little fishy.




real 0m1.451s
user 0m0.347s
sys 0m2.553s


real 0m3.118s
user 0m1.194s
sys 0m4.450s

and the C executable is nearly a couple of orders of magnitude smaller . . but the source code is a few times bigger . .



Your C code will dynamically link its standard library, but the Rust code will not.


also, better do strip before comparing executable sizes.