- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Description
This could have the same causes of Issue 42808 (i.e. regression due to #42313), or perhaps not.
This small test program solves the Euler problem number 214:
#![feature(step_by)]
fn main() {
    fn e214() -> u64 {
        const N_MAX: usize = 40_000_000;
        const SIZE: usize = N_MAX / 2;
        const LEN: u8 = 25;
        let mut chain_length = vec![2u8; SIZE];
        let mut tot: u64 = 0;
        for i in 1 .. SIZE {
            // if not prime, then try next one
            if chain_length[i] > 2 { continue; }
            // p is prime
            let p = 2 * i + 1;
            // calculate q*2^k = p-1
            let mut q = i;
            let mut k = 1;
            while (q & 1) == 0 {
                q /= 2;
                k += 1;
            }
            // calculate cl = chain_length(p)
            let cl = chain_length[q / 2] + k;
            // add p to tot if the length matches.
            if cl == LEN { tot += p as u64; }
            // loop over powers of p.
            let mut pp = p as u64;
            while pp < N_MAX as u64 {
                // Loop over multiples of pp.
                for j in ((pp / 2) .. SIZE as u64).step_by(pp) {
                    chain_length[j as usize] += cl - 2;
                }
                pp *= p as u64;
            }
        }
        tot
    }
    assert_eq!(e214(), 1_677_366_278_943);
}
On my PC using nightly-2017-06-18-x86_64-pc-windows-gnu it runs in about 0.39 seconds, while using a more recent Nightly, like the current rustc 1.19.0-nightly (78d8416 2017-06-17), it runs in about 0.87 seconds.
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.