Deleting specific characters from a string
Fredrik Lundh
fredrik at pythonware.com
Fri Jul 11 03:36:47 EDT 2003
Jeff Hinrichs wrote:
> First off, (holding hat in hand), I reread the profile module and then set
> my profiler up correctly with the proper bias setting.
you *cannot* use the profiler to measure overall execution time; it's
designed to let you know where the program spends most of its time,
not to compare different algorithms.
use 2.3's timeit script, or write your own timing loop. with timeit, I
get these results:
> python timeit.py -s "import string; text = 'ben at orange?enter&your&code';
delete = '@&'; table = string.maketrans('', '')" "result = text.translate(table,
delete)"
100000 loops, best of 3: 13.9 usec per loop
> python timeit.py -s "text = 'ben at orange?enter&your&code'; delete = '@&'"
"result = text" "for c in delete: result = result.replace(c, '')"
10000 loops, best of 3: 48.4 usec per loop
</F>
More information about the Python-list
mailing list