1

I would like to speed up a SimPy simulation (if possible), but I'm not sure the best way to insert timers to even see what is taking long.

Is there a way to do this?

josiekre
  • 795
  • 1
  • 7
  • 19
  • I would recommend using `runsnakerun` , which uses cProfile(there are directions on runsnakerun's webpage) – Joran Beasley May 13 '15 at 22:04
  • I will try this out. In the meantime, I found information in the docs about the [real time environment](http://simpy.readthedocs.org/en/latest/topical_guides/real-time-simulations.html). It specifically states it can be used to analyze the real-time behavior of an algorithm. Any experience with this? – josiekre May 13 '15 at 22:16
  • I dont think that does what you think it does :P ... I stand by my earlier suggestion :P – Joran Beasley May 13 '15 at 22:18
  • It probably doesn't since I can't wrap my brain around quite how it would work. You might be your comment in an answer below. – josiekre May 13 '15 at 22:20

2 Answers2

1

I would recommend using runsnakerun (or I guess snakeviz in py3x), which uses cProfile(there are directions on runsnakerun's webpage)

basically you just run your program

python -m cProfile -o profile.dump my_main.py 

then you can get a nice visual view of your profile with runsnake (or snakeviz if using py3)

python runsnakerun.py profile.dump

(note that running it in profile mode will probably slow down your code even more ... but its really just to identify slow parts)

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • Unfortunately `runsnakerun` is not compatible with Python 3.x; nor is it being maintained anymore. I've found `snakeviz` that is, and it is still in active development. Consider updating your answer? Thanks – josiekre May 14 '15 at 14:16
0
import time
t1 = time.time()
#code to time
t2 = time.time()
print(t2 - t1)

You can use this and compare the times with all code samples you want to test

Felix Schütz
  • 1,130
  • 1
  • 12
  • 25
JGerulskis
  • 800
  • 2
  • 10
  • 24
  • ummm while this is true for simple stuff I dont think this is going to be very helpful to the OP ... time/memory profiling `simpy` is going to take significantly more work :P) – Joran Beasley May 13 '15 at 22:07
  • Regardless of the code complexity, this will time it and that is what the OP has asked for @JoranBeasley. Care to clarify OP? – JGerulskis May 13 '15 at 22:10
  • sympy is implemented largely in C ... please advise what parts of sympy are taking up most of the time, using this method – Joran Beasley May 13 '15 at 22:12
  • This is a way to look at it. It has me thinking. But @JoranBeasley is right in that gaining actionable knowledge about the methods within the `simpy` simulation using this method would take a heck of a lot of `time.time()` statements and a sophisticated system to track them all. – josiekre May 13 '15 at 22:15
  • Alright my apologizes i'll remove the post shortly. Thanks for the clarification – JGerulskis May 13 '15 at 22:15
  • Don't remove the post. I am actually using both answers to get at what I need. So I think it's worth keeping here. – josiekre May 14 '15 at 16:02
  • @JGerulskis : Hi, can't fix your typo in `t2 - t2`. (Edits must be at least 6 characters). Can you? – mkiever Mar 10 '17 at 21:24