May 27, 2012
ok, can't seem to reproduce the crashing. now on to optimizing my sieve a bit more ,9 miliseconds for 1_000_000 is still to slow.
--
Er is zon buiten. Zonnige zondag namiddag met priemgetallen in de
plaats van buiten zitten. Tss tss. :-)
hoe? wie? x)
May 28, 2012
On Sunday, 27 May 2012 at 17:00:01 UTC, maarten van damme wrote:
> ok, can't seem to reproduce the crashing. now on to optimizing my
> sieve a bit more ,9 miliseconds for 1_000_000 is still to slow.
> --
> Er is zon buiten. Zonnige zondag namiddag met priemgetallen in de
> plaats van buiten zitten. Tss tss. :-)
> hoe? wie? x)

Have you tried turning optimization on? I get about 8ms with
your code with no flags and about 2.9 with -O -inline -release.

To optimize it further you could make a sieve that only works
with odd numbers. I get (https://gist.github.com/2817289) about
1ms that way. I'm sure it is possible to do much better, but
that would probably be much more work too.
May 28, 2012
I tried using 6k+-1 for all primes and for some reason it performed
slower. I think I have something completely inefficient somewhere,
can't figure out where though.
I think it has something to do with me increasing k and then
multiplying with k while I could have simply added 6 to K...

and I haven't tried with optimization on, first I want to get the algorithm as good as possible before trying to squeeze out those extra milliseconds :)
May 28, 2012
> I tried using 6k+-1 for all primes and for some reason it performed
> slower. I think I have something completely inefficient somewhere,
> can't figure out where though.

You aren't, by any chance, using divisions or remainders? those
are much slower than, say, multiplications (unless the divisor
is a power of two and known at compile time, in which case
the compiler will optimize them to bitwise operations).

> and I haven't tried with optimization on, first I want to get the
> algorithm as good as possible before trying to squeeze out those extra
> milliseconds :)

I prefer to compile with optimizations on when trying to
optimize something. That way I don't waste my time on
micro-optimizations that the compiler could do for me.
May 28, 2012
I didn't use divisions or remainders, only multiplications. I've changed it so it only uses addition and now it still doesn't outperform a version that only checks odd's. it's not as fast as your version where every index corresponds to i*2+1 because I fill every even number with false...
1 2
Next ›   Last »