Alternate approach but leaving the complexities that would cause varying execution times for the tested script, foo_a.pl (that's left as the proverbial challenge for the OP). Note also the caveat at LN9 of the script immediately below:

#!/usr/bin/perl -w use strict; use Time::HiRes qw[ time ]; # OP: "I have a perl script that I need to run 1000 times and for each + run # I need to store how much time it took to run... " # using foo_a.pl, execute this from foo_a's dir # Timings of foo_a.pl are NOT precise because they include the time # to execute the calculations here. my $begin = time; for my $arg( 1..1000 ) { my $start = time; system "perl foo_a.pl $arg"; my $duration = (time - $start); print "\n\t\$arg: $arg, \t\$start: $start, \t\$duration: $duration +\n"; $start = time; } print "$begin" . time . "\n"; exit;

foo_a.pl, an (almost) empty script:

#! /usr/bin/perl -w use strict; #foo_a.pl print "--foo_a.pl's marker inserted when run at LN11 in 1173964_a.pl: +"; exit;

And the output of D:\_Perl_\PMonks>D:\_Perl_\PMonks\1173964_a.pl > 1173964_a_OUT.pl on (Win7, AS 5.18), edited as noted:

--foo_a.pl's marker inserted when run at LN11 in 1173964_a.pl: $arg: 1, $start: 1476409956.16692, $duration: 0.0165810585 +021973 --foo_a.pl's marker inserted when run at LN11 in 1173964_a.pl: $arg: 2, $start: 1476409956.18353, $duration: 0.0134079456 +329346 --foo_a.pl's marker inserted when run at LN11 in 1173964_a.pl: $arg: 3, $start: 1476409956.19695, $duration: 0.0137300491 +333008 --foo_a.pl's marker inserted when run at LN11 in 1173964_a.pl: $arg: 4, $start: 1476409956.2107, $duration: 0.01424980163 +57422 # elided for brevity and henceforward, "marker inserted" lines deleted +: $arg: 495, $start: 1476409962.28221, $duration: 0.01291704 +17785645 $arg: 496, $start: 1476409962.29514, $duration: 0.01339387 +89367676 $arg: 497, $start: 1476409962.30855, $duration: 0.01174592 +97180176 $arg: 498, $start: 1476409962.32031, $duration: 0.01395082 +47375488 $arg: 499, $start: 1476409962.33427, $duration: 0.01355600 +35705566 $arg: 500, $start: 1476409962.34784, $duration: 0.01249790 +19165039 $arg: 501, $start: 1476409962.36035, $duration: 0.01373386 +38305664 $arg: 502, $start: 1476409962.3741, $duration: 0.012020826 +3397217 $arg: 503, $start: 1476409962.38613, $duration: 0.01191496 +84906006 $arg: 504, $start: 1476409962.39807, $duration: 0.01241683 +95996094 $arg: 505, $start: 1476409962.4105, $duration: 0.012879133 +2244873 # another long stretch omitted... $arg: 995, $start: 1476409968.50899, $duration: 0.01135301 +58996582 $arg: 996, $start: 1476409968.52035, $duration: 0.01180887 +22229004 $arg: 997, $start: 1476409968.53218, $duration: 0.01137590 +4083252 $arg: 998, $start: 1476409968.54356, $duration: 0.01149606 +70471191 $arg: 999, $start: 1476409968.55507, $duration: 0.01226401 +32904053 $arg: 1000, $start: 1476409968.56735, $duration: 0.0137550 +830841064

NB: initial "begin time": 1476409956.16692; time completed: 1476409968.58113 or roughly 12 seconds for 1000 iterations of foo_a.pl measured this way ... and yes, I see the command line is unnecessarily redundant... but so (perhaps) is this node.



If you didn't program your executable by toggling in binary, it wasn't really programming!

In reply to Re: Run a script multiple times and store the running time by ww
in thread Run a script multiple times and store the running time by Anonymous Monk

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.