Skip to content

Instantly share code, notes, and snippets.

@fphilipe
Created Aug 17, 2011
Embed
What would you like to do?
Fixnum
user system total real
true
0.030000 0.000000 0.030000 ( 0.027810)
true
0.010000 0.000000 0.010000 ( 0.006959)
--------------------------------------------------
String
user system total real
true
0.030000 0.000000 0.030000 ( 0.027461)
true
0.000000 0.000000 0.000000 ( 0.007344)
--------------------------------------------------
Array
user system total real
true
0.030000 0.000000 0.030000 ( 0.027043)
true
0.010000 0.000000 0.010000 ( 0.007165)
--------------------------------------------------
Hash
user system total real
true
0.020000 0.000000 0.020000 ( 0.026982)
true
0.010000 0.000000 0.010000 ( 0.007160)
--------------------------------------------------
Range
user system total real
true
0.030000 0.000000 0.030000 ( 0.026966)
true
0.010000 0.000000 0.010000 ( 0.007119)
--------------------------------------------------
Symbol
user system total real
true
0.020000 0.000000 0.020000 ( 0.027621)
true
0.010000 0.000000 0.010000 ( 0.006903)
--------------------------------------------------
Regexp
user system total real
true
0.030000 0.000000 0.030000 ( 0.026712)
true
0.000000 0.000000 0.000000 ( 0.007167)
--------------------------------------------------
Class
user system total real
true
0.030000 0.000000 0.030000 ( 0.027748)
true
0.010000 0.000000 0.010000 ( 0.007405)
--------------------------------------------------
Object
user system total real
true
0.030000 0.000000 0.030000 ( 0.027256)
true
0.000000 0.000000 0.000000 ( 0.006655)
--------------------------------------------------
require 'benchmark'
x = [
123,
'abc',
[9, 'z'],
{ :y => 8 },
1..100,
:sym,
/\Atest(?:|ing)\z/,
Object,
Object.new
]
x.each do |i|
puts i.class
a = b = nil
Benchmark.bm do |bm|
bm.report do
100_000.times do
a, b = [i] * 2
end
puts a.object_id == b.object_id
end
bm.report do
100_000.times do
a = b = i
end
puts a.object_id == b.object_id
end
end
puts '-' * 50
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment