When I'm learning a new language one of the programs I write is a simple
sieve of Eratosthenes; the julia code is shown below.
Julia is taking 70% longer than python 2.7.5 to execute the program - have
I coded something incorrectly?
Language Execution time (seconds) C 0.106 pypy 0.323
Did you code this up in Python too? There's a built-in Julia function
called primes (written in pure
Juliahttps://github.com/JuliaLang/julia/blob/master/base/primes.jl),
which implements a prime number sieve efficiently:
julia @time primes(1000);
elapsed time: 0.167461201 seconds (6581064
On Thursday, February 13, 2014 10:34:32 AM UTC-5, Stefan Karpinski wrote:
Did you code this up in Python too? There's a built-in Julia function
called primes (written in pure
Juliahttps://github.com/JuliaLang/julia/blob/master/base/primes.jl),
which implements a prime number sieve
Thanks for the quick reply. Yes these were all hand coded in Julia, python,
and C - same algorithm.
Version 0.1.2
02f3159-Linux-amd64 (2013-05-15 23:25:17)
I was timing from the shell, my function is much faster timed from within
julia:
julia @time myprimes(1000)
elapsed time:
Hmm. I guess there's probably a fair amount of overhead from all that
BitArray twiddling. I wonder if we should switch to using a full array of
integers in the algorithm for smaller N. The BitArray thing is mostly good
for large N where the list of primes is going to be much smaller than the
list
On Thursday, February 13, 2014 10:57:20 AM UTC-5, Steven G. Johnson wrote:
for i in 1:sieveTo
Note that you can speed it up a bit more (by ~0.01s on my machine) by
changing this to
@inbounds for i in 1:sieveTo
to turn off bounds-checking in the loop (since all the array indices
That actually doesn't help at all on my system. We ought to be inlining the
array accesses, in which case LLVM can probably eliminate the bounds checks
automatically.
On Thu, Feb 13, 2014 at 11:01 AM, Steven G. Johnson
stevenj@gmail.comwrote:
On Thursday, February 13, 2014 10:57:20 AM