From: Kirk Haines Date: 2002-02-08T05:13:39+09:00 Subject: Why is one slower than the other? ------=_MYMIY0qw?9.n70vi7Z?-8jxCSVh_6K9Lq7bFyDHUXtG7t2lE3hhdTk+:?wkg Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Program A: z = 0 t = "0123456789abcdefghijklmnopqrstuvwxyz" (0..999999).each { z += 1 if t =~ /abc/ } Program B: z = 0 t = "0123456789abcdefghijklmnopqrstuvwxyz" rexp = Regexp.new('abc'); (0..999999).each { z += 1 if rexp.match t } B has a runtime that is about 1.7 times A. Why? This is on Ruby 1.6.6 on a Linux box. Kirk Haines ------=_MYMIY0qw?9.n70vi7Z?-8jxCSVh_6K9Lq7bFyDHUXtG7t2lE3hhdTk+:?wkg Content-Type: application/octet-stream; name="" Content-Disposition: attachment; filename="" Content-Transfer-Encoding: base64 DQo= ------=_MYMIY0qw?9.n70vi7Z?-8jxCSVh_6K9Lq7bFyDHUXtG7t2lE3hhdTk+:?wkg--