ruby-changes:8085
From: ko1 <ko1@a...>
Date: Sun, 28 Sep 2008 20:21:31 +0900 (JST)
Subject: [ruby-changes:8085] Ruby:r19611 (ricsin): * ricsin/benchmark.rcb: add benchmarks.
ko1 2008-09-28 20:21:23 +0900 (Sun, 28 Sep 2008) New Revision: 19611 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19611 Log: * ricsin/benchmark.rcb: add benchmarks. Modified files: branches/ricsin/ricsin/ChangeLog branches/ricsin/ricsin/benchmark.rcb Index: ricsin/ricsin/benchmark.rcb =================================================================== --- ricsin/ricsin/benchmark.rcb (revision 19610) +++ ricsin/ricsin/benchmark.rcb (revision 19611) @@ -35,28 +35,24 @@ puts [cm-lo, ri-lo].join("\t") end -bench1() - -__END__ - __Cdecl__ %q{ #define FIX_PP(i) i += 2 #define FIX_CMP_LT(x, y) ((SIGNED_VALUE)(x) < (SIGNED_VALUE)(y)) } class Array - def each2 + def each_ricsin return self.enum_for(:each) unless block_given? i = 0 e = nil #C for (; FIX2LONG(i) < RARRAY_LEN(self); FIX_PP(i)) { #C e = RARRAY_PTR(self)[FIX2LONG(i)]; - yield e + yield e #C } self end - def each3 + def each_ruby i = 0 while i < self.length yield self[i] @@ -66,7 +62,8 @@ end class Fixnum - def times2 + alias each times + def each_ricsin return self.enum_for(:times) unless block_given? i = 0 #C for (; FIX_CMP_LT(i, self); FIX_PP(i)) { @@ -75,7 +72,7 @@ i end - def times3 + def each_ruby i = 0 while i < self yield i @@ -86,7 +83,7 @@ end class Range - def each2 + def each_ricsin return self.enum_for(:each) unless block_given? i = self.first e = self.last @@ -99,7 +96,7 @@ self end - def each3 + def each_ruby i = self.first e = self.last e += 1 if self.exclude_end? @@ -113,7 +110,39 @@ end end +def bench2 + max = 10_000_000 + [[Array.new(max), :each], [(1..max), :each], [max, :times]].each{|obj, mid| + begin + bm 'cfunc' do + obj.each{} + end + bm 'ricsin' do + obj.each_ricsin{} + end + bm 'ruby' do + obj.each_ruby{} + end + bm 'cfunc+cb' do + obj.each(&__Cb__('')) + end + bm 'ricsin+cb' do + obj.each_ricsin(&__Cb__('')) + end + bm 'ruby+cb' do + obj.each_ruby(&__Cb__('')) + end + ensure + # + end + } +end + +#bench1() +bench2() + +__END__ ### require 'benchmark' Index: ricsin/ricsin/ChangeLog =================================================================== --- ricsin/ricsin/ChangeLog (revision 19610) +++ ricsin/ricsin/ChangeLog (revision 19611) @@ -1,3 +1,7 @@ +Sun Sep 28 20:20:44 2008 Koichi Sasada <ko1@a...> + + * ricsin/benchmark.rcb: add benchmarks. + Sun Sep 28 19:55:54 2008 Koichi Sasada <ko1@a...> * ricsin/benchmark.rcb: add some benchmarks. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/