sorry joedio, but you are wrong ;)
at first, both sample has same loop - one
and faster example has much more regexp (each checkox placed in
different table cell, and a lot of different elements on page)
and if in slow code add printout (like puts c.id, each next puts get
more time, looks like each next took time of all previously and self
time)
and especially for you
src = array of 500 elements where 111 match regexp
def Z1(src)
cc=0
src.each do |l|
next unless l =~ /ctl00_cph_rpt.*?Notif.*?_eml_ctl\d+_chkEmail/
cc+=1
end
cc
end
Benchmark.bm(7) do |x|
x.report("z1:") { (1..10000).each { Z1($src) }}
end
user system total real
z1: 20.500000 0.010000 20.510000 ( 20.515719)
execution time about 20 second, there a MUCH more regex and loops than
in my first code ;)
> I wouldn't say its a bug, but that its a fine example of how
> different coding techniques can affect performance.
> Thus it makes sense that the second example will run faster:
> Less loops means faster execution
> Fewer RegExp checks also means faster execution
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]