1

I'm looking for a test script in Python to test a few things to see how fast/slow it completes on various systems.

Just some simple commands that are looped to make the script take say 10 second to complete and a report of how much cpu it uses, how much memory and how long it took to complete?

I guess for the memory part we would use memory_profiler, I guess psutil for the cpu calling out 5 readings one at the start (all separated by 2 seconds) then the average cpu usage used, 1 in the middle of the script and 5 at the end (all separated by 2 seconds)

How best would I go about this or is there already a script avaliable, I can't find anything that is good enough for this.

1 Answer 1

1

IPython has %timeit:

%timeit foo()

line_profiler and memory_profiler can be run from the IPython console:

%load_ext line_profiler
%load_exp memory_profiler

%lprun -f foo foo()
%mprun -f foo foo()

More details: http://www.huyng.com/posts/python-performance-analysis/

Average CPU is... trickier. Linux does report a kind of average CPU usage over time, check this: https://unix.stackexchange.com/questions/145247/understanding-cpu-while-running-top-command

Sign up to request clarification or add additional context in comments.

3 Comments

Problem is I can't use iPython in my situation.
@Ryflex: ipython's %timeit is just a simplified way to use timeit.repeat which is part of the Python batteries available everywhere. Only difference is repeat requires the setup to import everything it needs (including stuff from __main__ where %timeit gets the stuff from __main__ automatically), and requires you to tweak number yourself instead of autoranging, but the feature is available no matter what.
@Ryflex IPython just makes it easier. Check out the link I provided, you can do all of this without IPython.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.