6
submitted 10 months ago* (last edited 10 months ago) by axzxc1236@lemm.ee to c/python@programming.dev

I can't give you the code because this is work related, and I couldn't make a minimal code that mimics the behavior.

My of my programs at work is a log parser, it reads syslog and use compiled regex pattern to match syslog, the whole program looks like this

If match := pattern.match(line):
  Do this
elif match := pattern2.match(line):
  Do that
…

During almost two years of me developing the programs, there are more patterns and more things to do and it gets slower.

But I recently figure out that if I commented out Do that and replace it with pass, my program speeds up, even if pattern2 never matches in my test case.

More strange thing is that in my attempts to use cProfile to profile things, my program runs 2.5x to 3x faster by just doing

from cProfile import Profile
with Profile() as profile:
  main()

I don't even call anything with profile variable and it speeds up my program, why is that?

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here
this post was submitted on 23 Oct 2023
6 points (100.0% liked)

Python

6127 readers
7 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS