Created
October 27, 2010 15:28
-
-
Save hasclass/649256 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
class Foo | |
def method_missing(method_name, *args) | |
if method_name.match(/foo_bar/) | |
# code | |
else | |
super(method_name, *args) | |
end | |
end | |
end | |
GC.disable # Don't let GarbageCollector change outcome | |
Benchmark.bm(40) do |b| | |
n = 100_000 | |
normal_objects = n.times.map{Object.new} | |
foo_objects = n.times.map{Foo.new} | |
b.report("flatten Object objects") { normal_objects.flatten } | |
b.report("flatten Foo objects") { foo_objects.flatten } | |
end | |
GC.enable | |
# Results | |
# user system total real | |
# flatten Object objects 0.000000 0.000000 0.000000 ( 0.013034) | |
# flatten Foo objects 3.740000 1.560000 5.300000 ( 11.905745) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment