mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-03-30 17:43:26 +08:00
add benchmark for Rational
This commit is contained in:
@@ -28,4 +28,7 @@ autorelease_pool { bm_string }
|
||||
puts "*** Time ***"
|
||||
autorelease_pool { bm_time }
|
||||
|
||||
puts "*** Rational ***"
|
||||
autorelease_pool { bm_rational }
|
||||
|
||||
exit(0)
|
||||
|
||||
9
test/Benchmark/app/benchmark/rational.rb
Normal file
9
test/Benchmark/app/benchmark/rational.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
def bm_rational
|
||||
Benchmark.benchmark("", 30, "%r\n") do |x|
|
||||
rational_new(x)
|
||||
rational_plus(x)
|
||||
rational_minus(x)
|
||||
rational_divide(x)
|
||||
rational_multiply(x)
|
||||
end
|
||||
end
|
||||
21
test/Benchmark/app/benchmark/rational/divide.rb
Normal file
21
test/Benchmark/app/benchmark/rational/divide.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
def rational_divide(x)
|
||||
rat1 = Rational(3, 2.5)
|
||||
rat2 = Rational(3, 4)
|
||||
x.report "/ Rational" do
|
||||
500000.times do
|
||||
rat1 / rat2
|
||||
end
|
||||
end
|
||||
|
||||
x.report "/ Fixnum" do
|
||||
500000.times do
|
||||
rat1 / 10
|
||||
end
|
||||
end
|
||||
|
||||
x.report "/ Float" do
|
||||
500000.times do
|
||||
rat1 / 4.5
|
||||
end
|
||||
end
|
||||
end
|
||||
21
test/Benchmark/app/benchmark/rational/minus.rb
Normal file
21
test/Benchmark/app/benchmark/rational/minus.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
def rational_minus(x)
|
||||
rat1 = Rational(3, 2.5)
|
||||
rat2 = Rational(3, 4)
|
||||
x.report "- Rational" do
|
||||
500000.times do
|
||||
rat1 - rat2
|
||||
end
|
||||
end
|
||||
|
||||
x.report "- Fixnum" do
|
||||
500000.times do
|
||||
rat1 - 10
|
||||
end
|
||||
end
|
||||
|
||||
x.report "- Float" do
|
||||
500000.times do
|
||||
rat1 - 4.5
|
||||
end
|
||||
end
|
||||
end
|
||||
21
test/Benchmark/app/benchmark/rational/multiply.rb
Normal file
21
test/Benchmark/app/benchmark/rational/multiply.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
def rational_multiply(x)
|
||||
rat1 = Rational(3, 2.5)
|
||||
rat2 = Rational(3, 4)
|
||||
x.report "* Rational" do
|
||||
500000.times do
|
||||
rat1 * rat2
|
||||
end
|
||||
end
|
||||
|
||||
x.report "* Fixnum" do
|
||||
500000.times do
|
||||
rat1 * 10
|
||||
end
|
||||
end
|
||||
|
||||
x.report "* Float" do
|
||||
500000.times do
|
||||
rat1 * 4.5
|
||||
end
|
||||
end
|
||||
end
|
||||
8
test/Benchmark/app/benchmark/rational/new.rb
Normal file
8
test/Benchmark/app/benchmark/rational/new.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
def rational_new(x)
|
||||
x.report "Rational(x, y)" do
|
||||
200000.times do
|
||||
Rational(3, 2.5)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
21
test/Benchmark/app/benchmark/rational/plus.rb
Normal file
21
test/Benchmark/app/benchmark/rational/plus.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
def rational_plus(x)
|
||||
rat1 = Rational(3, 2.5)
|
||||
rat2 = Rational(3, 4)
|
||||
x.report "+ Rational" do
|
||||
500000.times do
|
||||
rat1 + rat2
|
||||
end
|
||||
end
|
||||
|
||||
x.report "+ Fixnum" do
|
||||
500000.times do
|
||||
rat1 + 10
|
||||
end
|
||||
end
|
||||
|
||||
x.report "+ Float" do
|
||||
500000.times do
|
||||
rat1 + 4.5
|
||||
end
|
||||
end
|
||||
end
|
||||
2
vm
2
vm
Submodule vm updated: 91ab4d371a...e146f16b26
Reference in New Issue
Block a user