Skip to content

Codon slower than CPython in task with pattern matching #624

Open
@rikfarrow

Description

@rikfarrow

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions