Speculative: Rust for base system components
Alejandro Martinez
unledev at gmail.com
Tue Jan 8 00:11:21 UTC 2019
Hi Brian,
On Fri, Jan 4, 2019 at 4:50 PM Brian Neal <brian at aceshardware.com> wrote:
>
> Sure!
>
> Just go to http://godbolt.org/ and type a small program in each language, enter the appropriate compilation flags and compare the output. The function I used took a count as a parameter, iterated through the count, summed up odd numbers and returned the sum.
I did the test with what I understood must had been the code you used,
but my results are different. See [1].
> >> It was a debug build with no optimization for either compiler. But we
> >> can easily run a variety of settings for comparison:
Debug builds show also panic and overflow checks for Rust sources,
which explains the difference in instruction count.
> >>
> >> Compiler Flags Inst. Count Build Time
> >> ======================================================================
> >> clang 7.0.0 none 33 296ms
> >> -O3 23 341ms
> >> rustc 1.31.0 none 110 606ms
> >> -C opt-level=3 67 643ms
> >> gcc 8.2 none 37 211ms
> >> -O2 24 249ms
> >> -O3 119* 206ms
> >>
> >> * With -O3, gcc unrolled and vectorized the loop. The other compilers
> >> did not emit vectorized code at any of the standard optimization levels.
I did not see this. Actually I had to force Rust with extra flags to
stop it from emitting such code.
In fact, both Rust and clang generate the exact same code for the
equivalent function.
> >> So, essentially, double the build time and ~3 times the code for the
> >> same logic.
This is not true in the tests I did wrt instruction count. The
compiler is certainly slower, although not sure it is 2x slower than
clang.
In fact, as you can see, there's one implementation in Rust that beats
the C code in inst count for both gcc and clang.
That said, instruction count is hardly a good metric, especially with
relatively recent CPUs.
My 2c: these tests focus on a very narrow set of properties and cases
that IMO should not be the basis for considering a language.
[1] https://godbolt.org/z/hqi_VX.
Cheers,
Alex
More information about the freebsd-hackers
mailing list