Skip to content

Adding --emit=asm speeds up generated code because of codegen units #57235

Open
@jrmuizel

Description

@jrmuizel

With the following rust code:

pub fn main() {
    print_triples();
    println!("hello");
}


fn print_triples() {
    let mut i = 0 as i32;
    for z in 1.. {
        for x in 1..=z {
            for y in x..=z {
                if x*x + y*y == z*z {
                    i = i + 1;
                    if i == 1000 {
                        return;
                    }
                }
            }
        }
    }
}

I get:

/tmp/pythagoras$ rustc --emit=link -O simple.rs
/tmp/pythagoras$ time ./simple
hello

real	0m0.290s
user	0m0.287s
sys	0m0.002s
/tmp/pythagoras$ rustc --emit=asm,link -O simple.rs
/tmp/pythagoras$ time ./simple
hello

real	0m0.005s
user	0m0.002s
sys	0m0.002s
/tmp/pythagoras$ rustc --version
rustc 1.32.0-nightly (400c2bc5e 2018-11-27)
/tmp/pythagoras$

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-driverArea: rustc_driver that ties everything together into the `rustc` compilerC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions