Languages
[Edit]
EN

Python - test algorithm performance

4 points
Created by:
eyllanesc
517

In this article, we would like to show how to test algorithms' performance in Python.

Usually, when we compare algorithms that execution times are short, we repeat computations multiple times to get precise results. The number of repeats is selected empirically. The source code that is not an algorithm part shouldn't be measured.

Main concept:

Hint: presented concept describes only a simple way how to test performance - in practice tests made by benchmarks are more complex.

 

Practical example

Edit

In the below example we compare algorithms that computes Fibonacci sequence values.

In the test, we made 1000 repeats on Fibonacci algorithms using Ryzen 9 x5900 processor and Python 3.10 (CPyhyon) under Windows 11 x64.

Test result:

Conclusion: iterative algorithm is 10 times slower in the tested cases.

Test source code:

 

Alternative titles

  1. Python - how to test algorithm performance?
  2. Python - test source code performance
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join