sobering observation, python vs. perl

Charles T. Smith cts.private.yahoo at gmail.com
Thu Mar 17 12:15:03 EDT 2016


On Thu, 17 Mar 2016 21:18:43 +0530, srinivas devaki wrote:

> please upload the log file,


Sorry, it's work stuff, can't do that, but just take any big set of files
and change the strings appropriately and the numbers should be equivalent.


> 
> 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.

#!/usr/bin/env python
# vim: tw=0
import sys
import re

def faster ():
    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)
                    continue
                #match = re.match (".*release_req", line)
                match = relreq.match (line)
                if match:
                    #print "%s: %s" % (tn, line),
                    print tn

faster()

$ time python ./find-relreq *.out | sort -u
TestCase_F_00_P
TestCase_F_00_S
TestCase_F_01_S
TestCase_F_02_M

real    0m25.515s
user    0m25.294s
sys     0m0.136s

3 more seconds!




More information about the Python-list mailing list