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. #!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 :-| } }, }); __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 # ===== Want to unsubscribe from this list? # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org