in reply to what is the difference between index and rindex
fwiw, rindex appears to be slightly faster:
use Benchmark qw(timethese); my $s = "abcdefg"; timethese( 6_000_000, { rindex => sub { my $i = rindex( $s, "cde" ) }, index => sub { my $i = index( $s, "cde" ) }, } );
Benchmark: timing 6000000 iterations of index, rindex...their functional difference is that rindex starts from the end of the string, and index starts at the beginning. there is no difference in their usage.
index: 1 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU) @ 5263157.89/s (n=6000000)
rindex: 1 wallclock secs ( 1.02 usr + 0.00 sys = 1.02 CPU) @ 5882352.94/s (n=6000000)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: what is the difference between index and rindex
by ikegami (Patriarch) on Sep 06, 2006 at 16:05 UTC |
In Section
Seekers of Perl Wisdom