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

[MacPerl] Re: Benchmarking



At 9:46 PM 11/14/00, Scott R. Godin wrote:
>on 11/14/2000 03:20 PM, Ronald J Kimball at rjk@linguist.dartmouth.edu
>wrote:
>>[snip]
>>  The difference between using s/// and tr/// is actually rather significant.
>
>Is it possible to write the
>
>     s/([a-z0-9])/$replace{$1}/g;
>
>in a tr/// form? It's my understanding at this point (and I could be wrong)
>that you have to write it as an eval, but I don't know whether you can
>assign the result of that to a variable, using =~ .. anyone know?

I've lost the reason you're not using reverse. It seems to me that in 
your original post, it didn't work because you had the construct
   $this =~ reverse $that;
which doesn't work because you used the binding operator. The 
solution was to say
   $this = reverse $that;

Below is the same benchmark test you just used, as modified by 
Ronald, and with a third option "Reverse' also tested, which gives me 
the following output:

Benchmark: timing 10000 iterations of Reverse, Substitute, Trans...
    Reverse:  3 secs ( 2.27 usr  0.00 sys =  2.27 cpu)
Substitute: 42 secs (42.85 usr  0.00 sys = 42.85 cpu)
      Trans:  3 secs ( 2.35 usr  0.00 sys =  2.35 cpu)

reverse is the fastest, and very simple to incorporate into your script.

#!perl -w

use strict;
use Benchmark;

my @DATA = <DATA>;
my @tmp;
my $x;
my %replace;

@replace{'a' .. 'z'} = reverse 'a' .. 'z';
@replace{'0' .. '9'} = reverse '0' .. '9';

timethese(10000 << (shift || 0), {
     'Substitute' =>
sub {
   for (@tmp = @DATA) {
     s/([a-z0-9])/$replace{$1}/g;
   }
},
     'Trans' =>
sub {
   for (@tmp = @DATA) {
 
tr/abcdefghijklmnopqrstuvwxyz0123456789/zyxwvutsrqponmlkjihgfedcba9876543210/; 
# damn linewrapping :-|
   }
},
     'Reverse' =>
sub {
   for (@tmp = @DATA) {
     $x = reverse
       }
},
});

__DATA__
dm-)(dome.zip
dm-[dl]-bloodpool.zip
dm-[pcf]biohazard.zip
dm-[tech]labyrinth.zip
dm-[tech]labyrinthv2.zip
dm_lightray.zip
dm-007archives.zip
dm-007basement.zip
dm-007caves.zip
dm-007complex.zip
dm-007egyptian.zip
[snippage...]
dm-wz5-revolution.zip
dm-wzarena1.zip
dm-xenon][.zip
dm-xfiles.zip
dm-xisorspalace.zip
dm-xortion.zip
dm-xtrememeasures.zip
dm-yougan.zip
dm-youtoo.zip
dm-zahltag_ut_addon.zip
dm-zaxisfreestyle.zip
dm-zaxisvirtuality.zip
dm-zeitkind-pro-addon.zip
dm-zyklotron.zip
- Bruce

__Bruce_Van_Allen____831__429_1688__
__PO_Box_839__Santa_Cruz_CA__95061__


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org