So I guess it must be highly platform-dependent then. I'm using perl 5.8.0 on Mac OS X (darwin 6.3) on a PPC G3 (iBook).Benchmark: timing 1000000 iterations of index, s///, substr... index: 15 wallclock secs (14.02 usr + 0.00 sys = 14.02 CPU) @ 71 +326.68/s (n=1000000) s///: 13 wallclock secs (12.33 usr + 0.00 sys = 12.33 CPU) @ 81 +103.00/s (n=1000000) substr: 14 wallclock secs (13.37 usr + 0.00 sys = 13.37 CPU) @ 74 +794.32/s (n=1000000) Rate index substr s/// index 71327/s -- -5% -12% substr 74794/s 5% -- -8% s/// 81103/s 14% 8% --
Assuming you're using x86, a possible explanation would be that doing regex might benefit from the PPC's rich number of general-purpose registers, while the x86's memory-oriented instruction set is perhaps more suited at executing the (stack-based) perl opcodes.
But it's just a guess...
•Update: I'm enclosing all my benchmark stuff in readmore-tags to avoid cluttering the thread
In reply to Re: Re: Re: Re: Regex matching on anywhere but the beginning or end of a line
by xmath
in thread Regex matching on anywhere but the beginning or end of a line
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |