Last active
August 29, 2015 14:18
-
-
Save korun/1a9a1a42338cb4edfda1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
n = 1_000_000 | |
login = 'login' | |
time = Time.now.to_i | |
Benchmark.bmbm 20 do |results| | |
results.report 'cycle' do | |
n.times do | |
end | |
end | |
# result: 3 array object usage | |
results.report '[] + []' do | |
n.times do | |
[login, time] + [3, 4, 5] | |
end | |
end | |
# result: 2 array object usage | |
results.report '[].push(*[])' do | |
n.times do | |
[login, time].push(*[3, 4, 5]) | |
end | |
end | |
# result: 1 array object usage | |
results.report '[].unshift(a, b)' do | |
n.times do | |
[3, 4, 5].unshift(login, time) | |
end | |
end | |
end |
Author
korun
commented
Apr 2, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment