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');"


In reply to Re: How expensive is reverse? by maverick
in thread How expensive is reverse? by bless$self=>perlmonks;

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.