Re: Simple integer math benchmark

new topic     » goto parent     » topic index » view thread      » older message » newer message
fizzpopsoft said...

What do they say... ?
There are lies, bloody lies and benchmarks! ;)
But thanks for the effort.

I did say take it with a grain of salt smile

fizzpopsoft said...

Pity there is no Java on that benchmark.

I can do something about that .....

class primes { 
    public static void main(String[] args) { 
        int n, lim; 
        int k; 
        int pc; 
        boolean is_prime; 
 
        pc = 0; 
        n = 1; 
        lim = 5000000; 
        while (n < lim) { 
            k=3; 
            is_prime=true; 
            n=n+2; 
            while ((k*k<=n) && (is_prime)) { 
                is_prime=n/k*k!=n; 
                k=k+2; 
            } 
            if (is_prime) { 
                pc = pc + 1; 
            } 
        } 
        System.out.print(pc); 
    } 
} 

1.48 seconds.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu