sobering observation, python vs. perl
Anders J. Munch
2016 at jmunch.dk
Thu Mar 17 17:27:19 EDT 2016
Charles T. Smith:
> I've really learned to love working with python, but it's too soon
> to pack perl away. I was amazed at how long a simple file search took
> so I ran some statistics:
Write Python in pythonic style instead of translated-from-Perl style, and the
tables are turned:
$ cat find-rel.py
| import sys
| def main():
| for fn in sys.argv[1:]:
| tn = None
| with open(fn, 'rt') as fd:
| for line in fd:
| if ' is ready' in line:
| tn = line.split(' is ready', 1)[0]
| elif 'release_req' in line:
| print tn
| main()
$ time python find-rel.py *.out
real 0m0.647s
user 0m0.616s
sys 0m0.029s
$ time perl find-rel.pl *.out
real 0m0.935s
user 0m0.910s
sys 0m0.023s
I don't have your log files and my quickly assembled test file doesn't actually
contain the phrase 'release_req', so my results may be misleading. Perhaps
you'll try it and post your results?
regards, Anders
More information about the Python-list
mailing list