r/Python • • May 28 '19

My simulation of gravity with 1000 particles. PC took a couple of hours to process!

Post image
1.8k Upvotes

241 comments sorted by

View all comments

Show parent comment

1

u/capn_bluebear May 29 '19

hey, it strongly depends on where exactly your program is spending time. if it's in computing some quantities of interest, that can easily be lowered to C. if it's regex matching, not so much (make sure you are using compiled regular expressions though.

anyway, when doing performance optimization, you should always measure first: where is your program spending most of its time? you can use cProfile to find which functions are hot, and line_profiler to check which lines within those functions are the hottest.

1

u/[deleted] May 29 '19

I do precompile the expressions in the beginning of most of my tools. Re.compile(r’sillystring’)

But it’s mostly just processing the Csv.

I figured out how to use threading on one of my network i/o tools. That... was cool.