mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-05-18 12:02:19 +08:00
Merge branch 'master' of github.com:lrz/RubyMotion
This commit is contained in:
@@ -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)
|
||||
|
||||
12
test/Benchmark/app/benchmark/time.rb
Normal file
12
test/Benchmark/app/benchmark/time.rb
Normal 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
|
||||
13
test/Benchmark/app/benchmark/time/at.rb
Normal file
13
test/Benchmark/app/benchmark/time/at.rb
Normal 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
|
||||
22
test/Benchmark/app/benchmark/time/comparable.rb
Normal file
22
test/Benchmark/app/benchmark/time/comparable.rb
Normal 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
|
||||
16
test/Benchmark/app/benchmark/time/minus.rb
Normal file
16
test/Benchmark/app/benchmark/time/minus.rb
Normal 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
|
||||
7
test/Benchmark/app/benchmark/time/now.rb
Normal file
7
test/Benchmark/app/benchmark/time/now.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
def time_now(x)
|
||||
x.report "now" do
|
||||
100000.times do
|
||||
Time.now
|
||||
end
|
||||
end
|
||||
end
|
||||
16
test/Benchmark/app/benchmark/time/plus.rb
Normal file
16
test/Benchmark/app/benchmark/time/plus.rb
Normal 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
|
||||
8
test/Benchmark/app/benchmark/time/strftime.rb
Normal file
8
test/Benchmark/app/benchmark/time/strftime.rb
Normal 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
|
||||
8
test/Benchmark/app/benchmark/time/to_f.rb
Normal file
8
test/Benchmark/app/benchmark/time/to_f.rb
Normal 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
|
||||
8
test/Benchmark/app/benchmark/time/to_i.rb
Normal file
8
test/Benchmark/app/benchmark/time/to_i.rb
Normal 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
|
||||
@@ -1,3 +1,7 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
def autorelease_pool(&block)
|
||||
block.call
|
||||
end
|
||||
|
||||
load './app/benchmark.rb'
|
||||
|
||||
Reference in New Issue
Block a user