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
In reply to Re: Faster with my keyword or no ?
by cavac
in thread Faster with my keyword or no ?
by abdan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |