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
assertstatements 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
timeitmagic 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
dismodule in optimization? - In the
exercise.pyfile, 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?