please upload the log file, and global variables in python are slow, so just keep all that in a function and try again. generally i get 20-30% time improvement by doin that.
On Thu, Mar 17, 2016 at 8:59 PM, Charles T. Smith <cts.private.ya...@gmail.com> wrote: > 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: > > $ time python find-rel.py > ./find-relreq *.out | sort -u > TestCase_F_00_P > TestCase_F_00_S > TestCase_F_01_S > TestCase_F_02_M > > real 1m4.581s > user 1m4.412s > sys 0m0.140s > > > $ time python find-rel.py > # modified to use precompiled REs: > TestCase_F_00_P > TestCase_F_00_S > TestCase_F_01_S > TestCase_F_02_M > > real 0m29.337s > user 0m29.174s > sys 0m0.100s > > > $ time perl find-rel.pl > find-relreq.pl *.out | sort -u > TestCase_F_00_P > TestCase_F_00_S > TestCase_F_01_S > TestCase_F_02_M > > real 0m5.009s > user 0m4.932s > sys 0m0.072s > > Here's the programs: > > #!/usr/bin/env python > # vim: tw=0 > import sys > import re > > isready = re.compile ("(.*) is ready") > relreq = re.compile (".*release_req") > for fn in sys.argv[1:]: # logfile name > tn = None > with open (fn) as fd: > for line in fd: > #match = re.match ("(.*) is ready", line) > match = isready.match (line) > if match: > tn = match.group(1) > #match = re.match (".*release_req", line) > match = relreq.match (line) > if match: > #print "%s: %s" % (tn, line), > print tn > > vs. > > while (<>) { > if (/(.*) is ready/) { > $tn = $1; > } > elsif (/release_req/) { > print "$tn\n"; > } > } > > Look at those numbers: > 1 minute for python without precompiled REs > 1/2 minute with precompiled REs > 5 seconds with perl. > -- > https://mail.python.org/mailman/listinfo/python-list -- Regards Srinivas Devaki Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad) Computer Science and Engineering Department ph: +91 9491 383 249 telegram_id: @eightnoteight -- https://mail.python.org/mailman/listinfo/python-list