A quick test implementing the Sieve of Eratostenes in Go.
It searches for prime numbers up to the specified limit, optionally saving them to file.
It is one of many small programs I wrote to get a feel for #golang. If you're interested in generating prime numbers, you should probably look into primegen or some other, more suitable alternative.
$ go build primes.go
primes [-l limit] [-s]
- -l limit (default 100000) Upper limit for prime searching
- -s (default false) Save the prime numbers to primes.txt
$ go test
These are some non-accurate benchmarks I ran on my machine.
Specs
- AMD Phenom II X6 1055T @3.4GHz
- 8GB of cheap Kingston DDR3 @486MHz
- Windows 8 RTM 64-bit
Results
Ram usage and CPU time for finding primes up to:
1'000'000 <1MB 2ms
10'000'000 <1MB 26ms
100'000'000 7.4MB 397ms
1'000'000'000 61.2MB 8.72s
10'000'000'000 599.8MB 1m49s
Copyright 2012 Martino di Filippo
Licensed under the MIT License