Drool 4: Benchmark your Python code better
Think about the last time you were solving a problem! Did you have more than 1 approach to solve it?
Don’t know about life, but Python has a great module to help you decide the better (fastest) way to solve a problem.
Let me introduce you to the timeit module. You can use it directly on your command line or any Python IDLE.
On the command line
python3 -m timeit '"-".join(char for char in "Pylenin")'
>>> 1000000 loops, best of 3: 0.851 usec per loop
On a Python IDLE
>>> import timeit
>>> timeit.timeit('"-".join(str(n) for n in range(100))', number=10000)
>>> 0.8187260627746582
Read about this topic in more detail in this blog.
Python timeit Module(With Examples)
Do you like what I send you? Then why not help me grow our community?
Share Pydrools with your friends and ask them to join us.
In the meantime, follow Pydrools on twitter.