After more than a decade of optimizing the perl interpreter for modern usage (e.g. use strict;), it seems Perl is significantly faster when using "my". Here are my test results:

cavac@earthrise:~/src/temp$ ./speedtest.sh Speedtest bash script: #!/bin/bash echo "Speedtest bash script:" cat speedtest.sh echo echo Perl version: perl -v | grep version echo echo "Warming up CPU to operating temp" cat speedtest_warmup.pl time perl speedtest_warmup.pl echo time perl speedtest_warmup.pl echo "########### Modern perl: strict and warnings enabled ########### +#" cat speedtest1.pl echo time perl speedtest1.pl echo "########### Outdated: my variables, but no strict and warnings # +#######" cat speedtest2.pl echo time perl speedtest2.pl echo "########### Noob perl: no strict, warnings or my variables ##### +##" cat speedtest3.pl echo time perl speedtest3.pl Perl version: This is perl 5, version 34, subversion 0 (v5.34.0) built for x86_64-li +nux Warming up CPU to operating temp #!/usr/bin/env perl # Just to get system load and CPU temp up to test conditions use strict; use warnings; my $total = 0; for(my $i = 0; $i < 200_000_000; $i++) { $total++; } real 0m14,558s user 0m14,543s sys 0m0,004s real 0m14,845s user 0m14,833s sys 0m0,008s ########### Modern perl: strict and warnings enabled ############ #!/usr/bin/env perl # STRICT & WARNINGS + MY # use strict; use warnings; my $total = 0; for(my $i = 0; $i < 300_000_000; $i++) { $total++; } real 0m22,095s user 0m22,086s sys 0m0,004s ########### Outdated: my variables, but no strict and warnings ####### +# #!/usr/bin/env perl # MY WITHOUT STRICT AND WARNINGS # my $total = 0; for(my $i = 0; $i < 300_000_000; $i++) { $total++; } real 0m21,943s user 0m21,938s sys 0m0,000s ########### Noob perl: no strict, warnings or my variables ####### #!/usr/bin/env perl # NOOBIE VERSION WITHOUT STRICT; WARNINGS AND MY # $total = 0; for($i = 0; $i < 300_000_000; $i++) { $total++; } real 0m41,117s user 0m41,100s sys 0m0,008s

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

In reply to Re: Faster with my keyword or no ? by cavac
in thread Faster with my keyword or no ? by abdan

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.