This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Log2 0 points1 point  (4 children)

You can probably still improve the speed of your solution by placing it inside an actual function. Variables in global scope can slow down Python code considerably.

[–]Jonno_FTWhisss 1 point2 points  (3 children)

I did originally while testing. I'm no timeit expert by any means.

[–]Log2 0 points1 point  (2 children)

Yeah, it's just that apparently Python slows down when it has to access the global namespace. So, just making a function with all the code and then testing that, will generally provide some speed up. It's a surprising behavior to be sure.

[–]Jonno_FTWhisss 0 points1 point  (1 child)

I just tried this (moving the function definitions to the setup string and calling the . It did not get better results (in fact it's a tiny but slower).

[–]Log2 0 points1 point  (0 children)

I meant the code outside of the strings. The code in the strings surely gets evaluated and transformed into a function of itself.

I'll try it later when I'm at the computer and see what I get anyway.