Sergey,

I wouldn't say its a bug, but that its a fine example of how
different coding techniques can affect performance.

In your first code example Ruby has to perform the regular expression
check
once in each loop, on every element in the set (that's 111 loops and
111 checks).

While in your second example the RegExp check is only performed
once to limit the number of elements in the set.  Then only the
elements remaining in that subset are looped.
Thus there are both less RegExp checks and less loops to be performed.

Thus it makes sense that the second example will run faster:
    Less loops means faster execution
    Fewer RegExp checks also means faster execution

Joe

> $ie.checkboxes.each do |c|
>   next unless c.id =~ /ctl00_cph_rpt.*?Notif.*?_eml_ctl\d+_chkEmail/
>  $ie.checkbox(:id,c.id).set
> end
>
> execution time = 68 seconds
>
> but
> $ie.elements(:id,/ctl00_cph_rpt.*?Notif.*?_eml_ctl\d+_chkEmail/).each
> do |c|
>  $ie.checkbox(:id,c.id).set
> end
>
> execution time = 3 second
>
> maybe it's a bug ?
>
> p.s. IE6/IE9 winxp/WIn7
> ruby 1.8.7
> watir 1.8.1

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to