[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] File::Sort



Rich Morin wrote:

>aml@world.std.com (Andrew M. Langmead) sez:

>> This causes a lot more overhead than you probably want a sorting
>> routine to have. It has to dereference $r on each compare. ...

>You might want to do a small test to see if the typeglob makes a
>substantial difference.  Otherwise, leaving it out might be clearer.

Well, I'm sure that the results vary depending on the overhead of the
coderef itself, but it seems to be a big enough difference to justify
it. A longer running comparison routine would lessen the significance
calling overhead. I've checked it before on unix and unixlike boxes,
but this is the first time I've checked in with MacPerl. Macperl seems
to be a bit on the slower side (the typeglob aliased version takes
about 1/3 of the time, where others shave it down to almost 1/4) but
it still is significant.

The Code:

#!/usr/bin/perl -w

use Benchmark;
use vars qw(*subglob @array);

$file = shift;

open FILE, $file or die;
@array = <FILE>;
close FILE;

$sub = sub { $a cmp $b };
local(*subglob) = $sub;

timethese(1000, {
  do_deref => q/@sorted = sort {&$sub} @array/,
  do_glob  => q/@sorted = sort subglob @array/,
});

The dataset:

Was a 2900 line text file from an online catalog. (The first nice big
file to sort that I found) I could send the URL to anyone interested,
but I don't think that it should matter, really.

The results:

MacPerl 5.1.0r2 (Perl 5.00202) running on a Power Macintosh 7600/120
with MacOS:

Benchmark: timing 1000 iterations of do_deref, do_glob...
  do_deref: 1604 secs (1608.05 usr  0.00 sys = 1608.05 cpu)
   do_glob: 555 secs (556.45 usr  0.00 sys = 556.45 cpu)
 
Perl 5.004_01 running on a Challenge XL with IRIX:

Benchmark: timing 1000 iterations of do_deref, do_glob...
  do_deref: 749 secs (740.33 usr  1.18 sys = 741.51 cpu)
   do_glob: 223 secs (220.58 usr  0.22 sys = 220.80 cpu)

Perl 5.004 running on Pentium 166MHz runnix Linux:

Benchmark: timing 1000 iterations of do_deref, do_glob...
  do_deref: 469 secs (468.05 usr  0.70 sys = 468.75 cpu)
   do_glob: 121 secs (120.30 usr  0.00 sys = 120.30 cpu)

Linux running on an Intel 80386:
Benchmark: timing 1000 iterations of do_deref, do_glob...
  do_deref: 6416 secs (5829.70 usr 52.46 sys = 5882.16 cpu)
   do_glob: 2196 secs (2089.32 usr 14.75 sys = 2104.07 cpu)



-- 
Andrew Langmead

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch