Merge branch 'master' of github.com:lrz/RubyMotion

This commit is contained in:
Laurent Sansonetti
2013-11-21 18:42:13 +01:00
11 changed files with 121 additions and 4 deletions

View File

@@ -14,12 +14,15 @@ rescue
end
puts "*** Array ***"
bm_array
autorelease_pool { bm_array }
puts "*** Hash ***"
bm_hash
autorelease_pool { bm_hash }
puts "*** String ***"
bm_string
autorelease_pool { bm_string }
exit(0)
puts "*** Time ***"
autorelease_pool { bm_time }
exit(0)

View File

@@ -0,0 +1,12 @@
def bm_time
Benchmark.benchmark("", 30, "%r\n") do |x|
time_at(x)
time_comparable(x)
time_minus(x)
time_now(x)
time_plus(x)
time_strftime(x)
time_to_f(x)
time_to_i(x)
end
end

View File

@@ -0,0 +1,13 @@
def time_at(x)
x.report "at with small number" do
100000.times do |i|
Time.at(i)
end
end
x.report "at with large number" do
100000.times do |i|
Time.at(1000000 * i)
end
end
end

View File

@@ -0,0 +1,22 @@
def time_comparable(x)
time1 = Time.at(10000)
time2 = Time.at(10001)
x.report "<" do
100000.times do
time1 < time2
end
end
x.report ">" do
100000.times do
time1 > time2
end
end
x.report "==" do
100000.times do
time1 == time2
end
end
end

View File

@@ -0,0 +1,16 @@
def time_minus(x)
time1 = Time.at(10000)
time2 = Time.at(10001)
x.report "- fixnum" do
10000.times do
time1 + 100
end
end
x.report "- float" do
10000.times do
time1 + 123.45
end
end
end

View File

@@ -0,0 +1,7 @@
def time_now(x)
x.report "now" do
100000.times do
Time.now
end
end
end

View File

@@ -0,0 +1,16 @@
def time_plus(x)
time1 = Time.at(10000)
time2 = Time.at(10001)
x.report "+ fixnum" do
10000.times do
time1 + 100
end
end
x.report "+ float" do
10000.times do
time1 + 123.45
end
end
end

View File

@@ -0,0 +1,8 @@
def time_strftime(x)
x.report "strftime" do
time = Time.now
100000.times do
time.strftime('%m/%d/%Y')
end
end
end

View File

@@ -0,0 +1,8 @@
def time_to_f(x)
x.report "to_f" do
time = Time.now
100000.times do
time.to_f
end
end
end

View File

@@ -0,0 +1,8 @@
def time_to_i(x)
x.report "to_i" do
time = Time.now
100000.times do
time.to_i
end
end
end

View File

@@ -1,3 +1,7 @@
#!/usr/bin/env ruby
def autorelease_pool(&block)
block.call
end
load './app/benchmark.rb'