Created
September 28, 2012 09:01
-
-
Save shugo/3798760 to your computer and use it in GitHub Desktop.
benchmark for refinements
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" | |
N = 1000 | |
class Foo | |
def foo | |
end | |
end | |
class Bar | |
end | |
module BarExt | |
refine Bar do | |
def foo | |
end | |
end | |
end | |
module Baz | |
end | |
class Quux | |
include Baz | |
end | |
module BazExt | |
refine Baz do | |
def foo | |
end | |
end | |
end | |
call_foo_10000 = 10000.times.map { "x.foo" }.join("; ") | |
eval <<EOF | |
module Normal | |
def self.run | |
x = Foo.new | |
N.times do | |
#{call_foo_10000} | |
end | |
end | |
end | |
module RefineClass | |
using BarExt | |
def self.run | |
x = Bar.new | |
N.times do | |
#{call_foo_10000} | |
end | |
end | |
end | |
module RefineModule | |
using BazExt | |
def self.run | |
x = Quux.new | |
N.times do | |
#{call_foo_10000} | |
end | |
end | |
end | |
EOF | |
Benchmark.bmbm do |bm| | |
bm.report("normal") { Normal.run } | |
bm.report("refine class") { RefineClass.run } | |
bm.report("refine module") { RefineModule.run } | |
end |
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
diff --git a/vm_method.c b/vm_method.c | |
index e44782c..f9114bf 100644 | |
--- a/vm_method.c | |
+++ b/vm_method.c | |
@@ -468,6 +468,7 @@ rb_method_entry_t * | |
rb_method_entry_get_with_omod(VALUE omod, VALUE klass, ID id, | |
VALUE *defined_class_ptr) | |
{ | |
+#if 0 | |
struct cache_entry *ent; | |
ent = cache + EXPR1(klass, omod, id); | |
@@ -477,6 +478,7 @@ rb_method_entry_get_with_omod(VALUE omod, VALUE klass, ID id, | |
*defined_class_ptr = ent->defined_class; | |
return ent->me; | |
} | |
+#endif | |
return rb_method_entry_get_without_cache(klass, omod, id, | |
defined_class_ptr); | |
diff --git a/vm_opts.h b/vm_opts.h | |
index 9e357f4..6f193cc 100644 | |
--- a/vm_opts.h | |
+++ b/vm_opts.h | |
@@ -36,7 +36,7 @@ | |
/* VM running option */ | |
#define OPT_CHECKED_RUN 1 | |
-#define OPT_INLINE_METHOD_CACHE 1 | |
+#define OPT_INLINE_METHOD_CACHE 0 | |
#define OPT_BLOCKINLINING 0 | |
/* architecture independent, affects generated code */ |
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
Rehearsal ------------------------------------------------- | |
normal 2.500000 0.000000 2.500000 ( 2.495841) | |
refine class 2.920000 0.000000 2.920000 ( 2.928995) | |
refine module 6.690000 0.000000 6.690000 ( 6.684988) | |
--------------------------------------- total: 12.110000sec | |
user system total real | |
normal 2.420000 0.000000 2.420000 ( 2.432138) | |
refine class 2.930000 0.000000 2.930000 ( 2.921288) | |
refine module 6.370000 0.000000 6.370000 ( 6.373621) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment