Newsgroups: comp.lang.perl.misc
From: John Porter <jdpor...@min.net>
Date: 1998/10/02
Subject: Benchmark: ST vs OM
I've recently been benchmarking the relative performance of
the Schwartzian Transform (ST) (aka. map-sort-map) vs. the Orcish Maneuver (say "OR-cache"). I recently posted some results that indicate that ST is #!/usr/local/bin/perl -w # read 3100 7-letter words. shuffle them. sub control { # explicit comparison } sub control0 { # default comparison @out = sort @in } sub ST { @out = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, $_ ] } @in; } sub OM { my %c = (); # the cache @out = sort { ($c{$a} ||= $a) cmp ($c{$b} ||= $b) } @in; } timethese( 10, { 'ST' => \&ST, 'OM' => \&OM, 'ct' => \&control, 'c0' => \&control0, } ); sub shuffle { # the usual Fisher-Yates shuffle. my @i = @_; for my $i ( reverse ( 0 .. $#i ) ) { my $j = int( rand( $i )); @i[$i,$j] = @i[$j,$i]; } @i; } Benchmark: timing 10 iterations of OM, ST, c0, ct... OM: 33 secs (32.51 usr 0.05 sys = 32.56 cpu) ST: 30 secs (29.70 usr 0.09 sys = 29.79 cpu) c0: 2 secs ( 2.52 usr 0.00 sys = 2.52 cpu) ct: 12 secs (11.48 usr 0.00 sys = 11.48 cpu) In these tests, I am trying to compare the underlying -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||