in reply to japhy blabs about regexes (again)
Update: I cut 'n pasted the code and output, then fixed LTSAVE, then forgot to repaste. I guess no one looked closely enough to notice that LT_SAVE was actually beating LEADTRAIL. Its all fixed now though :)#!/usr/local/bin/perl -w use strict; use Benchmark; my $str = " a b c d "; timethese(-5, { LEADING=>\&leading, LEADTRAIL=>\&lead_trail, LTSAVE=>\<_save, SEXEGER=>\&sexeger, SINGLE_RE=>\&single_re, WHILE_RE=>\&while_sub, }); sub leading { local $_ = $str; s/^\s+//; $_; } sub lead_trail { local $_ = $str; s/^\s+|\s+$//g; $_; } sub lt_save { local $_ = $str; s/^\s*(.*?)\s*$/$1/; $_; } sub sexeger { local $_ = reverse $str; s/^\s+//; reverse $str; } sub single_re { local $_ = $str; s/\s+$//; $_; } sub while_sub { local $_ = $str; 1 while s/\s$//; $_; } ~/tst >./tst3 Benchmark: running LEADING, LEADTRAIL, LTSAVE, SEXEGER, SINGLE_RE, WHI +LE_RE, eac h for at least 5 CPU seconds... LEADING: 5 wallclock secs ( 5.00 usr + 0.00 sys = 5.00 CPU) @ 77 +596.80/s ( n=387984) LEADTRAIL: 5 wallclock secs ( 5.22 usr + 0.00 sys = 5.22 CPU) @ 26 +504.21/s ( n=138352) LTSAVE: 5 wallclock secs ( 5.18 usr + 0.00 sys = 5.18 CPU) @ 18 +690.54/s ( n=96817) SEXEGER: 4 wallclock secs ( 5.35 usr + 0.00 sys = 5.35 CPU) @ 57 +972.52/s ( n=310153) SINGLE_RE: 5 wallclock secs ( 5.23 usr + 0.00 sys = 5.23 CPU) @ 56 +434.42/s ( n=295152) WHILE_RE: 6 wallclock secs ( 5.00 usr + 0.00 sys = 5.00 CPU) @ 36 +090.00/s ( n=180450)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: japhy blabs about regexes (again)
by japhy (Canon) on Jul 16, 2001 at 23:07 UTC | |
by runrig (Abbot) on Jul 16, 2001 at 23:28 UTC |