Description
Codon is slower than CPython in a task with pattern matching
rik@nuke:~/Reports/GR$ time report > t2
real 0m6.443s
user 0m8.682s
sys 0m1.122s
rik@nuke:~/Reports/GR$ time report.py > t1
real 0m4.947s
user 0m4.419s
sys 0m0.510s
rik@nuke:~/Reports/GR$ wc -l weblogs
7282338 weblogs
report is "codon build report.py";
rik@nuke:~/Reports/GR$cat ~/bin/report.py
#!/usr/bin/python3
import re
with open('e') as file:
d = {}
# total number of hits; Codon [int]
total = 0
regexString = re.compile('/login.* H')
for line in file:
# Codon disliked: m = re.findall(regexString,line)
m = regexString.findall(line)
if len(m) > 0: # make sure there was a match
if re.search('destination=', m[0]):
continue # skip lines containing destination=
y = re.split(' ',m[0])
# add 1 to each dict entry, or init as 1
d[y[0]] = d.get(y[0], 0) + 1
# I took this from Karpathy on makemore, and the sort
# lambda where making -kv means a reverse order sort
# https://www.youtube.com/watch?v=PaCmpygFfXo 12:36
total = total+1
sorted_count=sorted(d.items(), key = lambda kv: -kv[1])
for item in sorted_count:
print(item[0], item[1])
print("Total number of hits: ", total)