I'm not sure how they are implemented or what the (O) is (I suspect it's O(n)). Here's what a quick benchmark says from my Dual Celeron 400:
#!/usr/bin/perl
use Benchmark;
@one = ('a' x 100);
@two = ('a' x 1000);
@three = ('a' x 10000);
timethese( 100000, {
'rev 100' => sub { reverse @one },
'rev 1000' => sub { reverse @two },
'rev 10000' => sub { reverse @three },
}
);
Gives me this:
Benchmark: timing 100000 iterations of rev 100, rev 1000, rev 10000...
rev 100: 1 wallclock secs ( 0.24 usr + 0.00 sys = 0.24 CPU) @ 41
+6666.67/s (n=100000)
(warning: too few iterations for a reliable count)
rev 1000: 1 wallclock secs ( 0.87 usr + 0.00 sys = 0.87 CPU) @ 11
+4942.53/s (n=100000)
rev 10000: 8 wallclock secs ( 7.65 usr + 0.00 sys = 7.65 CPU) @ 13
+071.90/s (n=100000)
At a 100,000 iterations of a 1,000 element list, it took 0.87 seconds of CPU time. Not too expensive I'd say.
Updated CRAP! nardo is quite right. I hate it when I make silly mistakes.
/\/\averick
perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"
|