top | item 5340869

(no title)

hndc | 13 years ago

You're using integer arithmetic in Ruby and floating-point arithmetic in Go. Try replacing

  math.Mod(float64(i), float64(j))
with

  i%j
My results:

  $ time go run primes.go
  Found them! 78702

  real	0m0.835s
  user	0m0.787s
  sys	0m0.039s

  $ time ruby primes.rb
  Found them! 78702

  real	0m21.013s
  user	0m21.005s
  sys	0m0.016s

discuss

order

agentS|13 years ago

It's worth noting that the time on the go side includes the time to run the compiler, and linker, since you're using `go run`, instead of `go build`. Not saying that's bad, just something to keep in mind when benchmark numbers are in the second range.

(I understand that you did because the original poster did it)