Skip to content

Instantly share code, notes, and snippets.

@havenwood havenwood/bench.md
Last active Dec 12, 2015

Embed
What would you like to do?
Entirely Unscientific Benchmark of Primes in Various Ruby Implementations

Unscientific Benchmark

The Benchmark

def is_prime? n
  (2...n).all? { |i| n % i != 0 }
end

def sexy_primes n
  (9..n).map do |i|
    [i - 6, i]
  end.select do |i|
    i.all? { |i| is_prime? i }
  end
end

a = Time.now
sexy_primes 100_000
b = Time.now

puts b - a

The Results

Topaz-dev

7.78 sec

Ruby-1.9.3-p392

45.38 sec

Ruby-2.0.0-p0

44.82 sec

JRuby-1.7.3

41.97 sec

Rbx-2.0.0-rc1

85.51 sec

Maglev-1.1.0-dev

23.97 sec

MacRuby-0.1.3

35.37 sec

MRuby-dev

262.25 sec (not compiled or performance optimized, just here for fun)

IronRuby-1.1.4 on Mono-2.10.10

429.36 sec

Copyright Shannon Skipper MIT or Ruby License

@ko1

This comment has been minimized.

Copy link

ko1 commented Feb 8, 2013

Can I add this script to MRI benchmark directory? (license?)

@asterite

This comment has been minimized.

Copy link

asterite commented Feb 8, 2013

@havenwood

This comment has been minimized.

Copy link
Owner Author

havenwood commented Feb 16, 2013

@ko1 Sorry for such a late reply, I just now saw your comment! Yes, please use the script for anything you'd like with any license you'd prefer!

@havenwood

This comment has been minimized.

Copy link
Owner Author

havenwood commented Feb 16, 2013

@asterite Wow, cool! I need to take a closer look at crystal for sure.

@asterite

This comment has been minimized.

Copy link

asterite commented Feb 17, 2013

@havenwood Thanks :-)

Just a small warning: Crystal is not a Ruby compiler. It's a different language (that happens to have almost the same syntax). And it's more limited than Ruby. And it's still in it's early development stage. And we don't know if it will work.

Topaz looks really good too. It's amazing that it's so fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.