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

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



on 11/14/2000 03:20 PM, Ronald J Kimball at rjk@linguist.dartmouth.edu
wrote:

> On Tue, Nov 14, 2000 at 01:10:39PM -0500, Scott R. Godin wrote:
>> 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)
> 
> I'm afraid you've made an error in your script that invalidates this
> benchmark.  After Substitute executes the first time, there is no input
> left on DATA to be read.  For all the remaining iterations, neither
> subroutine has any input to operate on.
> 
> Here's an improved Benchmark.  I read <DATA> into @DATA first.  In each
> iteration I copy the array to @tmp because otherwise the
> substitutions/translations would affect @DATA.  (In this case, that
> wouldn't really matter; every other iteration would just reverse the
> change.)
> 
> 
> Benchmark: timing 2048 iterations of Substitute, Trans...
> Substitute: 13 wallclock secs (12.49 usr +  0.02 sys = 12.51 CPU)
> Trans:  1 wallclock secs ( 0.57 usr +  0.00 sys =  0.57 CPU)
> 
> 
> 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?

Considering I have around 2,630 map names to deal with at present, I'm still
not certain how much time it saves or not. the .cgi SEEMS to still run
generally as fast as usual, only taking about 5 secs to iterate through the
largest segment of the maplist (the UT Deathmatch maps; around 1600-1700 or
so); the part that takes it the longest, is sending the actual HTML for this
portion, which tops out around 500K+

*aCk*, to put it mildly. bloody HTML. (growl)


> #!perl -w
> use strict;
> use Benchmark;
> 
> my @DATA = <DATA>;
> my @tmp;
> 
> my %replace;
> 
> @replace{'a' .. 'z'} = reverse 'a' .. 'z';
> @replace{'0' .. '9'} = reverse '0' .. '9';
> 
> timethese(1 << (shift || 0), {
> 'Substitute' =>
> sub {
> for (@tmp = @DATA) {
> s/([a-z0-9])/$replace{$1}/g;
> }
> },
> 'Trans' =>
> sub {
> for (@tmp = @DATA) {
> tr/abcdefghijklmnopqrstuvwxyz0123456789/zyxwvutsrqponmlkjihgfedcba9876543210/;
> # damn linewrapping :-|
> }
> },
> });

-- 
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