in reply to Re: Re: Removing commas and dollar signs from a variable.
in thread Removing commas and dollar signs from a variable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: next question...
by Juerd (Abbot) on Dec 22, 2001 at 01:11 UTC | |
I'll support my answer with a Benchmarked example:
This script's output:
Update 200112212151: I forgot to copy the string before removing the X'es. After the first iteration, there'd be no X'es left. For your entertainment, I present the previous version of my post: I was going to answer that tr/// was faster, and s/// can be used for more complex matches. I was going to support my answer with a Benchmarked example, which would show that tr/// was a lot faster. BUT my benchmark told me s/// is the winner. On 1 MB of random data, s/X//g is faster than tr/X//d. If anyone can tell me why this is, or what I'm doing wrong, I'd really appreciate that. This script's output:
| [reply] [d/l] [select] |
|
substitution speed vs transliteration speed
by boo_radley (Parson) on Dec 22, 2001 at 01:43 UTC | |
Benchmark: timing 500000 iterations of sub256, trn256...
sub256: 3 wallclock secs ( 3.84 usr + 0.00 sys = 3.84 CPU) @ 130208.33/s (n=500000)
trn256: 2 wallclock secs ( 1.81 usr + 0.00 sys = 1.81 CPU) @ 276243.09/s (n=500000)
Rate sub256 trn256
sub256 130208/s -- -53%
trn256 276243/s 112% --
----------------------------------------
Benchmark: timing 500000 iterations of sub1024, trn1024...
sub1024: 15 wallclock secs (14.56 usr + 0.00 sys = 14.56 CPU) @ 34340.66/s (n=500000)
trn1024: 6 wallclock secs ( 6.81 usr + 0.00 sys = 6.81 CPU) @ 73421.44/s (n=500000)
Rate sub1024 trn1024
sub1024 34341/s -- -53%
trn1024 73421/s 114% --
----------------------------------------
Benchmark: timing 500000 iterations of sub5k, trn5k...
sub5k: 66 wallclock secs (65.36 usr + 0.00 sys = 65.36 CPU) @ 7649.94/s (n=500000)
trn5k: 31 wallclock secs (30.64 usr + 0.00 sys = 30.64 CPU) @ 16318.54/s (n=500000)
Rate sub5k trn5k
sub5k 7650/s -- -53%
trn5k 16319/s 113% --
----------------------------------------
| [reply] [d/l] |
|
Re: next question...
by mrbbking (Hermit) on Dec 22, 2001 at 01:20 UTC | |
s///; uses the regex engine. Straight substitution is relatively faster and 'cheaper'. | [reply] [d/l] [select] |
|
Re: next question...
by archen (Pilgrim) on Dec 22, 2001 at 04:51 UTC | |
| [reply] |