Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline range for all integral types #2557

Merged
merged 1 commit into from
Jun 9, 2012
Merged

Conversation

bstrie
Copy link
Contributor

@bstrie bstrie commented Jun 9, 2012

Here are the test files (blogbench-while.rs and blogbench-for.rs):

import io::writer_util;

fn main(args: [str]) {
    let count = option::get(int::from_str(args[1]));
    let rng = rand::seeded_rng(rand::seed());

    let fw = result::get(io::buffered_file_writer("vec_gen.out"));
    let mut i = 0;
    while i < count {
        let r = (rng.next() & 0x7fffffffu32) as uint;
        fw.write_uint(r);
        fw.write_char('\n');
        i += 1;
    }
}
import io::writer_util;

fn main(args: [str]) {
    let count = option::get(int::from_str(args[1]));
    let rng = rand::seeded_rng(rand::seed());

    let fw = result::get(io::buffered_file_writer("vec_gen.out"));
    for int::range(0, count) {|_i|
        let r = (rng.next() & 0x7fffffffu32) as uint;
        fw.write_uint(r);
        fw.write_char('\n');
    }
}

I compiled blogbench-for.rs twice, once with HEAD and once with my commit that forces the range function to inline. All files were compiled with --opt-level 3. Here are my unscientific results:

kibble@Dreamland:/media/warehouse/scrap
⌁ time ./blogbench-while 100000000 && time ./blogbench-for-old 100000000 && time ./blogbench-for-new 100000000

real    0m19.102s
user    0m13.873s
sys     0m0.288s

real    0m29.946s
user    0m21.481s
sys     0m0.644s

real    0m18.607s
user    0m12.957s
sys     0m0.368s

kibble@Dreamland:/media/warehouse/scrap
⌁ time ./blogbench-while 100000000 && time ./blogbench-for-old 100000000 && time ./blogbench-for-new 100000000

real    0m17.834s
user    0m12.973s
sys     0m0.308s

real    0m26.919s
user    0m19.281s
sys     0m0.460s

real    0m20.518s
user    0m14.393s
sys     0m0.364s

kibble@Dreamland:/media/warehouse/scrap
⌁ time ./blogbench-while 100000000 && time ./blogbench-for-old 100000000 && time ./blogbench-for-new 100000000

real    0m20.678s
user    0m14.997s
sys     0m0.408s

real    0m22.702s
user    0m16.633s
sys     0m0.372s

real    0m18.628s
user    0m13.073s
sys     0m0.312s

Across three trials, this commit decreases the execution time of int::range by an average of about 25%.

@bstrie
Copy link
Contributor Author

bstrie commented Jun 9, 2012

This is a followup to #2501.

brson added a commit that referenced this pull request Jun 9, 2012
Inline `range` for all integral types
@brson brson merged commit 629f1b2 into rust-lang:master Jun 9, 2012
oli-obk pushed a commit to oli-obk/rust that referenced this pull request Sep 21, 2022
celinval pushed a commit to celinval/rust-dev that referenced this pull request Jun 4, 2024
Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants