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

Benchmarking (was: Re: [MacPerl] crazy hoops to do something thatseems so simple?)



>on 11/14/2000 01:46 AM, Scott R. Godin at mactech@webdragon.net wrote:
>
>> on 11/11/2000 05:54 PM, Bart Lateur at bart.lateur@skynet.be wrote:
>> As for your problem, I think I'd do:
>> 
>> my %replace;
>> @replace{'a' .. 'z'} = reverse 'a' .. 'z';
>> s/([a-z])/$replace{$1}/g;
> 
> works for me, definitely, although I wound up doing it more like this, due to
> what I wanted:
> 
> my %replace;
> @replace{'a' .. 'z'} = reverse 'a' .. 'z';
> @replace{'0' .. '9'} = reverse '0' .. '9';
> #elsewhere
> $coercename =~ s/([a-z]|[0-9])/$replace{$1}/g;
> 
> the resultant yield again sorts properly, although It has been my
> understanding that tr/// was a great deal faster than s///
> 
> I'd have to run some benchmarking to be sure, but I get the impression that
> I'm still losing out here time-wise. if the CGI takes a lot of hits, the time
> can potentially stack up against me, at least in my understanding.

'some benchmarking' -- apparently, for a data-set of this size, the time
differences are more than negligible.

Benchmark: timing 1000000 iterations of Substitute, Trans...
Substitute: 20 secs (19.47 usr  0.00 sys = 19.47 cpu)
     Trans: 20 secs (18.80 usr  0.00 sys = 18.80 cpu)

script follows: 

#!perl -w
use strict;
    my %replace;
    @replace{'a' .. 'z'} = reverse 'a' .. 'z';
    @replace{'0' .. '9'} = reverse '0' .. '9';
use Benchmark;

timethese(1000000, {
    'Substitute' =>
sub {
  while (<DATA>) {
    s/([a-z]|[0-9])/$replace{$1}/g;
  }
},
    'Trans' =>
sub {
  while (<DATA>) {
  
tr/abcdefghijklmnopqrstuvwxyz0123456789/zyxwvutsrqponmlkjihgfedcba9876543210
/; # damn linewrapping :-|
  }
},
});

__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

(The data set can be imagined as 1676 map names from the utdm section of my
cgi - which you can actually see by going here
http://www.magpage.com/~sgodin/cgi-scripts/ncrp/ncmapslist.cgi and switching
to the utdm section from utassault (the default) via the popup menu. I
whipped up a short extraction script to dump the dataset in a file and then
c&p below __DATA__ in the actual test script.)

-- 
Scott R. Godin            | e-mail : mactech@webdragon.net
Laughing Dragon Services  |    web : http://www.webdragon.net/



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