Questions
- Arrange the following three items in order of importance when building a software application: correctness (the program does what it is supposed to do), efficiency (the program is optimized in speed and memory management), and functionality (the program runs).
- How could
assert
statements be used in Python to check for the correctness of a program? - What is a benchmark in the context of optimizing a software program?
- How could
timeit
magic commands be used in Python to estimate the speed of a piece of code? - List three different types of information that are recorded and returned by
cProfile
(included as output columns) in the context of profiling a program. - On a high level, what is the role of the
dis
module in optimization? - In the
exercise.py
file, we write a simple function,close()
, that checks whether a pair of particles are close to each other (with 1e-5 tolerance). Inbenchmark()
, we randomly initialize two particles and callclose()
after running the simulation. Make a guess of what takes most of the execution time inclose()
, and profile the function viabenchmark()
usingcProfile
; does the result confirm your guess?