Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save alphaKAI/1da14ae1ccc3d84d316e to your computer and use it in GitHub Desktop.

Select an option

Save alphaKAI/1da14ae1ccc3d84d316e to your computer and use it in GitHub Desktop.
斜辺が1000以下のピタゴラス数を求めるプログラム (ベンチマーク用)
#encoding:utf-8
max = 1000
class Pythagoras
def initialize(a, b, c)
@a = a
@b = b
@c = c
end
def array
[@a, @b, @c]
end
end
array = []
(1..max).each do |a|
(1..a).each do |b|
(1..b).each do |c|
if a*a == b*b + c*c
array << Pythagoras.new(a, b, c)
end
end
end
end
p array.map{|x| x.array}
Rubinius:
rubinius 2.5.2.c145 (2.1.0 50aa7356 2015-04-07 3.5.1 JI) [x86_64-darwin14.1.0]
./rubinius/bin/rbx pythagoras.rb 7.38s user 0.13s system 118% cpu 6.318 total
CRuby:
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
ruby pythagoras.rb 21.36s user 0.10s system 99% cpu 21.563 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment