Excellent :-)
> On Feb 13, 2014, at 11:09 AM, James King <[email protected]> wrote: > > OK, installed 0.2 binary from the juliareleases ppa, I get the primes builtin > now and I do notice faster startup time. Run time for sifting to 10 million > primes is about 0.11 seconds, very close to the O3 build of the C program. > >> On Thursday, February 13, 2014 10:52:19 AM UTC-5, Stefan Karpinski wrote: >> You're using an ancient version of Julia, first off. Please do try something >> more recent, like a 0.2 version or a 0.3 prerelease: >> http://julialang.org/downloads/. Julia has a significant amount of startup >> time (recently much reduced), you're comparing the time it takes for Julia >> to compile all of its standard library plus your function and then run your >> function. It's doing all of that less than 2x slower than Python is running >> the code. If you want more meaningful results, you should do the timing >> within the language, not from the shell. >> >> >>> On Thu, Feb 13, 2014 at 10:46 AM, James King <[email protected]> wrote: >>> Thanks for the quick reply. Yes these were all hand coded in Julia, python, >>> and C - same algorith >>> 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(10000000) >>> elapsed time: 0.23879289627075195 seconds >>> (about 2 x C time) >>> >>> I don't seem to have built in julia function for primes? >>> julia> primes(10000000) >>> ERROR: primes not defined >>> >>> perhaps I am missing some package? >>> >>> >>> C code below, in case you want to compare: >>> >>> #include <stdio.h> >>> #include <math.h> >>> #include <stdlib.h> >>> #include <stdint.h> >>> #include <assert.h> >>> #include <string.h> >>> >>> uint64_t sieve (uint64_t N) >>> { >>> uint64_t sieve_to = ceil(sqrt (N)); >>> uint64_t pi = 0; >>> uint8_t* S = malloc (sizeof (uint8_t) * (N + 1)); >>> uint64_t i, j; >>> memset (S, 1, sizeof (uint8_t) * N); >>> S[0] = 0; S[1] = 0; >>> >>> for (i = 1; i <= sieve_to; i++) >>> if (S[i] == 1) >>> for (j = i*i; j <= N; j += i) >>> S[j] = 0; >>> >>> for (i = 1; i<= N; i++) pi += S[i]; >>> free (S); >>> return (pi); >>> } >>> >>> >>> int main() >>> { >>> printf ("%lu\n", sieve(10000000)); >>> return(0); >>> } >>> >>> >>> >>> >>>> 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 Julia), which implements a prime number >>>> sieve efficiently: >>>> >>>> julia> @time primes(10000000); >>>> elapsed time: 0.167461201 seconds (6581064 bytes allocated) >>>> >>>> Obviously the times are apples to oranges since we're on different >>>> machines, but it looks to be comparable to your C version. Also, on my >>>> system, your version runs in much less time: >>>> >>>> julia> @time primes2(10000000); >>>> elapsed time: 0.185365732 seconds (80021608 bytes allocated) >>>> >>>> What version of Julia are you running and how are you timing it? Are you >>>> perchance timing the execution of the program from the shell? >>>> >>>> >>>>> On Thu, Feb 13, 2014 at 10:26 AM, James King <[email protected]> wrote: >>>>> 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 >>>>> python 1.26 >>>>> julia 2.177 >>>>> >>>>> >>>>> function primes(N) >>>>> sieveTo = ceil(sqrt(N)) >>>>> S = ones(N) >>>>> S[1] = 0 >>>>> for i in 1:sieveTo >>>>> if S[i] > 0 >>>>> for j in i*i:i:N >>>>> S[j] = 0 >>>>> end >>>>> end >>>>> end >>>>> return(sum(S)) >>>>> end >>>>> >>>>> println(primes(10000000)) >>>> >>
