oldgeezer wrote:
Hi all,
Hello,
Last week I discovered this perl.beginners group. Good stuff here, albeit many times hard to grasp the answers. But I'm learning.
If you have any questions just ask (the list.)
What I would like to understand is why looping 2 times through 5000 lines takes less time than looping 5000 times through 2 lines.
Because that is just the way things work. Keep that in mind if you ever have to optimise nested loops. And don't forget to benchmark any code to be sure that you have an objective metric.
To show what I mean, I wrote a snippet that does nothing with the data and yet the first part is 5 times faster than the second part (in my pc anyway).
On my PC it is 3 times faster.
#!/usr/bin/perl use strict; use warnings; use POSIX qw(clock); #just create a small array for this test my @few=(); for my $i(1...2){push @few, $i};
That is usually written as: my @few = 1 .. 2;
#just create a big array for this test my @many=(); for my $i(1...500000){push @many, $i};
That is usually written as: my @many = 1 .. 500_000; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/