There are a large number of tools that one can use to profile the performance of code in Python. The simplest option for most is the Unix time
command, which measures the amount of time or resources that executing a particular command requires. This recipe demonstrates the usage of this command.
Fortunately, the Unix time
command is available on virtually every Linux distribution and on OS X at the command line. The time
command is even available in Cygwin on Windows machines. Thus, you should be ready for this recipe.
Perform the following simple steps to conduct your first Python benchmark:
asa.py
.time python asa.py 1R0R.pdb
time
command will report back two to three pieces of information—depending on your operating system—that describe the length of time consumed by executing your code:12078.1 angstrom squared. python asa.py 1R0R.pdb 49.60s user 0.15s system 97% cpu 51.194 total
There isn't much complexity to the time
command, and it is a great tool to get a quick idea of how long a program or script takes to execute. As per the main page (enter man time
at the command line to access), the time utility has output-formatting options that allow you to see various metrics that describe the memory and input/output usage. Also, the output is a little bit cryptic. In this case, 51.194 total
is the elapsed actual time that the command took to complete with a 97%
CPU utilization. The user and sys time values can be ignored.
18.222.196.175