3 ms·
I had an experience the other day with ChatGPT and some Python code. I wanted to modify Gunicorn's logger class so I can filter out specific URL paths. Given i
by nickjj 1y ago
I had an experience the other day with ChatGPT and some Python code.
I wanted to modify Gunicorn's logger class so I can filter out specific URL paths. Given it's a hot code path (running on every request) I told it I made 3 solutions and was looking to see which one is the fastest. I used a list + loop using startswith, compiled regex and also used startswith while passing in a tuple of paths.
It produced me benchmark code and also benchmark results which stated the regex solution was the best and fastest solution using Python's standard library.
I didn't believe it so I ran the benchmark myself and the tuple version was over 5x faster than the regex solution.
I then told it I ran the benchmark and got different results and it almost word for word said something like "Oh right, thank you for the clarification, the tuple version is indeed the fastest!". It saved me a few minutes writing the benchmark code but yeah, I rarely trust its output for anything I'm not 100% on.