Perl never ceases to amaze me. After seeing Arien's point I wondered just how much slower it was to build a stack frame, do the assignment and knock the stack frame down again.

I've seen various references to "the overhead of calling a sub" and have been guilty of not sub-ing when I should have because of it. I needn't have worried. I was expecting a vastly higher overhead than this demonstrates!

#!perl -w use strict; use Benchmark; my @ary = 0 .. 100; Benchmark::cmpthese ( 10_000_000, { 'assignment' => '$ary[1] = -1;', 'splice' => 'splice @ary, 1, 1, -1;' } ); __END__ # Output C:\test>192779 Benchmark: timing 10000000 iterations of assignment, splice... assignment: 21 wallclock secs (19.65 usr + 0.00 sys = 19.65 CPU) @ 50 +8931.75/s (n=10000000) splice: 56 wallclock secs (57.13 usr + 0.01 sys = 57.14 CPU) @ 17 +4999.56/s (n=10000000) Rate splice assignment splice 175000/s -- -66% assignment 508932/s 191% --

What's this about a "crooked mitre"? I'm good at woodwork!

In reply to Re: Re(2): updating an array of strings by BrowserUk
in thread updating an array of strings by kirk123

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.