sobering observation, python vs. perl
Marko Rauhamaa
marko at pacujo.net
Thu Mar 17 11:47:55 EDT 2016
"Charles T. Smith" <cts.private.yahoo at gmail.com>:
> 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.
Can't comment on the numbers but the code segments are not quite
analogous. What about this one:
#!/usr/bin/env python
# vim: tw=0
import sys
import re
isready = re.compile("(.*) is ready")
for fn in sys.argv[1:]:
tn = None
with open(fn) as fd:
for line in fd:
match = isready.match(line)
if match:
tn = match.group(1)
elif "release_req" in line:
print tn
Marko
More information about the Python-list
mailing list