+ 2

Python program properties

Hey sololearners, I was recently programming and thought that is there any way possible that we can know the: 1. speed of a python program 2. memory usage of a python program

12th Sep 2020, 9:39 AM
Kunsh-Tyagi
Kunsh-Tyagi - avatar
4 Answers
+ 7
You can also use module timeit from python. This statement is from stackoverflow: timeit is more accurate (compared to time module), for three reasons: - it repeats the tests many times to eliminate the influence of other tasks on your machine, such as disk flushing and OS scheduling. - it disables the garbage collector to prevent that process from skewing the results by scheduling a collection run at an inopportune moment. - it picks the most accurate timer for your OS, time.time or time.clock in Python 2 and time.perf_counter() on Python 3. See timeit.default_timer.
12th Sep 2020, 10:34 AM
Lothar
Lothar - avatar
+ 2
And how can we know the memory used
12th Sep 2020, 11:02 AM
Kunsh-Tyagi
Kunsh-Tyagi - avatar
+ 1
using time or datetime modules you can see the speed of a program. Just make two time objects (one at the start and one at the end) and subtract them.
12th Sep 2020, 9:45 AM
Slick
Slick - avatar