fuzzyping has asked for the wisdom of the Perl Monks concerning the following question:
------------------------------------------------------------#!/usr/bin/perl # benchmark_test_strict.pl use Benchmark; use strict; my @test_array; open(IN, "testfile"); while (<IN>) { chomp; push(@test_array, $_); } close(IN); my $test_ref = \@test_array; my $t0 = timeit(2000, sub { my @var_results = sort {$a cmp $b} @test_a +rray; }); my $t1 = timeit(2000, sub { my @ref_results = sort {$a cmp $b} @$test_ +ref; }); my $td = timediff($t0, $t1); print "\n"; print "normal var (t0)\n"; print "===============\n"; print timestr($t0), "\n\n"; print "reference (t1)\n"; print "==============\n"; print timestr($t1), "\n\n"; print "difference (t0, t1)\n"; print "===================\n"; print timestr($td), "\n\n";
------------------------------------------------------------[fuzzy@jason fuzzy]$ perl benchmark_test_strict.pl normal var (t0) =============== 3 wallclock secs ( 3.11 usr + 0.00 sys = 3.11 CPU) @ 643.09/s (n=20 +00) reference (t1) ============== 3 wallclock secs ( 3.10 usr + 0.00 sys = 3.10 CPU) @ 645.16/s (n=20 +00) difference (t0, t1) =================== 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)
------------------------------------------------------------#!/usr/bin/perl # benchmark_test.pl use Benchmark; open(IN, "testfile"); while (<IN>) { chomp; push(@test_array, $_); } close(IN); $test_ref = \@test_array; $t0 = timeit(2000, sub { @var_results = sort {$a cmp $b} @test_array; +}); $t1 = timeit(2000, sub { @ref_results = sort {$a cmp $b} @$test_ref; } +); $td = timediff($t0, $t1); print "\n"; print "normal var (t0)\n"; print "===============\n"; print timestr($t0), "\n\n"; print "reference (t1)\n"; print "==============\n"; print timestr($t1), "\n\n"; print "difference (t0, t1)\n"; print "===================\n"; print timestr($td), "\n\n";
[fuzzy@jason fuzzy]$ perl benchmark_test.pl normal var (t0) =============== 4 wallclock secs ( 3.12 usr + 0.00 sys = 3.12 CPU) @ 641.03/s (n=20 +00) reference (t1) ============== 3 wallclock secs ( 3.50 usr + 0.01 sys = 3.51 CPU) @ 569.80/s (n=20 +00) difference (t0, t1) =================== 1 wallclock secs (-0.38 usr + -0.01 sys = -0.39 CPU)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Performance of Perl references
by perrin (Chancellor) on Jul 22, 2002 at 07:13 UTC | |
|
Re: Performance of Perl references
by kjherron (Pilgrim) on Jul 22, 2002 at 07:27 UTC | |
by fuzzyping (Chaplain) on Jul 22, 2002 at 13:57 UTC | |
by Felonious (Chaplain) on Jul 22, 2002 at 16:32 UTC | |
|
Re: Performance of Perl references
by grinder (Bishop) on Jul 22, 2002 at 08:41 UTC | |
|
Re: Performance of Perl references
by BUU (Prior) on Jul 22, 2002 at 07:42 UTC |