Date: Sun, 6 Jan 2019 09:01:07 -0700 From: Alan Somers <asomers@freebsd.org> To: Brian Neal <brian@aceshardware.com> Cc: Garance A Drosehn <drosih@rpi.edu>, "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: Re: Speculative: Rust for base system components Message-ID: <CAOtMX2gPrpO2O70pnwpU80bXMXo6LB9PCkU3bYw2ToMMnhf%2Bww@mail.gmail.com> In-Reply-To: <92bd5362-d898-aa12-8f3d-9fbe23f38e0c@aceshardware.com> References: <ca76e5f7-6e59-bd67-144a-90ad66f0252e@metricspace.net> <7d7bc47d-04cf-2f9b-00a3-e3d9d92b3623@aceshardware.com> <72922F2C-9D27-47AA-BB1C-2DA8589CF008@rpi.edu> <92bd5362-d898-aa12-8f3d-9fbe23f38e0c@aceshardware.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jan 1, 2019 at 12:00 AM Brian Neal <brian@aceshardware.com> wrote:
>
> It was a debug build with no optimization for either compiler. But we
> can easily run a variety of settings for comparison:
>
> 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.
>
> So, essentially, double the build time and ~3 times the code for the
> same logic.
I get different results on Godbolt. I don't know exactly what your
program was, but I tried to recreate it from your description. I
wrote it in two ways. With opt-level=s, I got 13 instructions for one
version, and 16 for the other. With opt-level=3, I got vectorized
code for both. Here's my code:
pub fn oddcount(num: i32) -> i32 {
(0..num).map(|i| {
if i % 2 > 0 {
i
} else {
0
}
}).sum()
}
pub fn oddcount2(num: i32) -> i32 {
let mut sum = 0;
for i in 0..num {
if i % 2 > 0 {
sum += i;
}
}
sum
}
-Alan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2gPrpO2O70pnwpU80bXMXo6LB9PCkU3bYw2ToMMnhf%2Bww>
