# $B54\<V%Q%U%)!\<%^%s%9(B

**URL:** <https://www.ruby-forum.com/t/b54-v-q-u-s-9-b/57694>\
**Category:** Development\
**Created:** [April 13, 2006, 3:12am UTC](https://www.ruby-forum.com/t/b54-v-q-u-s-9-b/57694 "2006-04-13T03:12:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yukihiro\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c57346/32.png) [@Yukihiro\_M](https://www.ruby-forum.com/u/Yukihiro_M)\
**Post date:** [April 13, 2006, 3:12am UTC](https://www.ruby-forum.com/t/b54-v-q-u-s-9-b/57694/1 "2006-04-13T03:12:47Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

[ruby-talk:188721]e$B$G!“0J2\<$N%W%m%0%i%`e(B(e$BFC$Ke(Bquxe$B$H8F$P$l$k%Q%?!\<e(B  
e$B%s$K$\*$$$Fe(B)1.9(e$B54\<Ve(B)e$B$,e(B1.8e$B$h$jCY$$$H$$$&;XE&$,$”$j$^$7$?!#e(B

e$B$\*CN$i$;$^$G!#e(B

@re = /^\w±\w+$/ # Some random expression  
def foo(str)  
str =~ @re  
end

def bar(str)  
str =~ /^\w±\w+$/  
end

def qux(str)  
str =~ Regexp.new("/^\w±\w+$/")  
end

require ‘benchmark’  
include Benchmark

bm(16) do |test|  
test.report(“foo”) do  
1\_000\_000.times {foo(“abc-xyz”)}  
end  
test.report(“bar”) do  
1\_000\_000.times {bar(“abc-xyz”)}  
end  
test.report(“qux”) do  
1\_000\_000.times {qux(“abc-xyz”)}  
end  
end

---

<div class="post-metadata">

**Author:** ![Yukihiro\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c57346/32.png) [@Yukihiro\_M](https://www.ruby-forum.com/u/Yukihiro_M)\
**Post date:** [April 13, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/b54-v-q-u-s-9-b/57694/2 "2006-04-13T16:11:37Z")

</div>

Yukihiro M. w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+$I$&$+!"0l1~8!F$$O$7$F$\_$^$9!#e(B

ruby 1.8.4 (2006-03-01) [i686-linux]  
user system total real  
foo 1.090000 0.100000 1.190000 ( 1.203012)  
bar 0.980000 0.040000 1.020000 ( 1.023069)  
qux new empty 1.570000 0.340000 1.910000 ( 1.943319)  
qux new 2.920000 1.870000 4.790000 ( 14.304892)  
qux search 0.470000 0.020000 0.490000 ( 1.712328)  
qux 3.150000 0.420000 3.570000 ( 21.151487)

ruby 1.9.0 (2006-03-01) [i686-linux]  
user system total real  
foo 0.980000 0.110000 1.090000 ( 1.101956)  
bar 0.890000 0.040000 0.930000 ( 0.944269)  
qux new empty 1.330000 0.340000 1.670000 ( 1.684494)  
qux new 6.240000 0.050000 6.290000 ( 6.378824)  
qux search 0.460000 0.000000 0.460000 ( 0.463881)  
qux 6.830000 0.010000 6.840000 ( 6.937301)

ruby 1.8.4 (2005-12-24) [i386-cygwin]  
user system total real  
foo 1.051000 0.010000 1.061000 ( 1.061000)  
bar 0.981000 0.000000 0.981000 ( 0.991000)  
qux new empty 2.053000 0.030000 2.083000 ( 2.083000)  
qux new 3.285000 0.280000 3.565000 ( 11.176000)  
qux search 0.341000 0.000000 0.341000 ( 0.360000)  
qux 3.595000 0.260000 3.855000 ( 14.581000)

ruby 1.9.0 (2006-04-08) [i386-cygwin]  
user system total real  
foo 1.041000 0.000000 1.041000 ( 1.061000)  
bar 0.961000 0.000000 0.961000 ( 0.961000)  
qux new empty 1.242000 0.030000 1.272000 ( 1.272000)  
qux new 4.997000 0.020000 5.017000 ( 5.017000)  
qux search 0.350000 0.000000 0.350000 ( 0.360000)  
qux 5.238000 0.000000 5.238000 ( 5.278000)

–  
e$B\>.Gwe(B

@re = /^\w±\w+$/ # Some random expression  
def foo(str)  
str =~ @re  
end

def bar(str)  
str =~ /^\w±\w+$/  
end

def qux(str)  
str =~ Regexp.new("/^\w±\w+$/")  
end

def qux\_new(str)  
Regexp.new("/^\w±\w+$/")  
end

def qux\_new\_empty(str)  
Regexp.new("")  
end

def qux\_search(str)  
str =~ //^\w±\w+$//  
end

require ‘benchmark’  
include Benchmark

N = 300\_000

bm(16) do |test|  
GC.disable

test.report(“foo”) do  
N.times {foo(“abc-xyz”)}  
end

GC.enable  
GC.start  
GC.disable

test.report(“bar”) do  
N.times {bar(“abc-xyz”)}  
end

GC.enable  
GC.start  
GC.disable

test.report(“qux new empty”) do  
N.times {qux\_new\_empty(“abc-xyz”)}  
end

GC.enable  
GC.start  
GC.disable

test.report(“qux new”) do  
N.times {qux\_new(“abc-xyz”)}  
end

GC.enable  
GC.start  
GC.disable

test.report(“qux search”) do  
N.times {qux\_search(“abc-xyz”)}  
end

GC.enable  
GC.start  
GC.disable

test.report(“qux”) do  
N.times {qux(“abc-xyz”)}  
end  
end

---

<div class="post-metadata">

**Author:** ![Yukihiro\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c57346/32.png) [@Yukihiro\_M](https://www.ruby-forum.com/u/Yukihiro_M)\
**Post date:** [April 13, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/b54-v-q-u-s-9-b/57694/3 "2006-04-13T17:28:35Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:28561] Re: e$B54\<V%Q%U%)!\<%^%s%9e(B”  
on Thu, 13 Apr 2006 23:11:13 +0900, “K.Kosako” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|quxe$B$,CY$$$N$O8!:w$G$O$J$/!"Kh2se(BRegexp.newe$B$7$F$$$ke(B  
|e$BItJ,$,860x$G$9!#$3$l$O!“54\<V$N$[$&$,:GE,2=\>pJs$Ne(B  
|e$B\<hF@$K;~4V$r$+$1$F$$$k$N$G!”@55,I=8=$N:n@.;~4V$,e(B  
|e$BD9$/$J$k$?$a$G$9!#e(B

e$B$J$k$[$I!"$3$N\>pJs$OEA$($F$\*$-$^$9!#e(B
