Jason Brownlee's Blog, page 13

October 26, 2023

How to Benchmark a Python Statement

You can benchmark Python statements using the time.perf_counter() function or the timeit module. Either method can be used to estimate the execution time of a Python code. Benchmarking is an important step when improving the execution speed of Python programs. Benchmark results provide hard numbers that can be reported and compared directly. This can help […]
 •  0 comments  •  flag
Share on Twitter
Published on October 26, 2023 11:00

October 25, 2023

Python Benchmarking Best Practices

You can help to ensure benchmark results are reliable, stable, and useful by following benchmarking best practices. This includes isolating the code and the execution environment and using benchmarking functions that are high-precision, non-adjustable, and monotonic. It also includes less obvious factors such as repeating benchmarks reporting summary statistics and warming up target code before […]
 •  0 comments  •  flag
Share on Twitter
Published on October 25, 2023 11:00

October 24, 2023

Tips When Presenting Benchmark Results

You can carefully choose the level of precision and units of measure when presenting benchmark results. These are the two main areas when presenting benchmark results that can introduce confusion and unnecessary cognitive load when attempting to interpret, analyze, and compare results. Getting precision and units of measure correct will go a long way to […]
 •  0 comments  •  flag
Share on Twitter
Published on October 24, 2023 11:00

October 23, 2023

Python Benchmark Unit Test

You can develop a benchmark unit test by defining a unit test that calculates the execution time of a target function and asserts that it is below a threshold. This can be used to automate performance testing to confirm target functions meet performance requirements and that code changes do not introduce regressions in performance. In […]
 •  0 comments  •  flag
Share on Twitter
Published on October 23, 2023 11:00

October 22, 2023

Importance of Python Execution Time Performance Benchmarking

Benchmarking the execution time is required to improve the performance of code. Code performance is a critical aspect of modern software development. Typically the performance of a program is a requirement of the project from the beginning, ensuring responses are timely and user experience is consistent. Therefore we cannot neglect performance benchmarking and the most […]
 •  0 comments  •  flag
Share on Twitter
Published on October 22, 2023 11:00

October 19, 2023

Repeat Benchmarks to Get Stable Results

You can improve the benchmark estimate by repeating a benchmark many times and reporting the average score. Each time a benchmark is performed, a different result will be reported. This is for many reasons such as other activity in the operating system, external dependencies, hardware behavior, and more. The result is an estimate of the […]
 •  0 comments  •  flag
Share on Twitter
Published on October 19, 2023 11:00

October 18, 2023

Concurrent File I/O 7-Day Course

File I/O can be so much faster with the careful use of concurrency. This includes using Python threads and processes to read, write, and copy files, as well as how to safely append to a file from multiple threads. This course provides you with a 7-day crash course in concurrency for File I/O. You will […]
 •  0 comments  •  flag
Share on Twitter
Published on October 18, 2023 11:00

October 17, 2023

Python Books on Execution Time Benchmarking

There are no books focused on benchmarking Python, at the time of writing. Nevertheless, many of the most popular books on Python and high-performance Python do have sections or examples of benchmarking Python. In this tutorial, we will summarize the books that cover the benchmarking of execution time in Python programs and the methods that […]
 •  0 comments  •  flag
Share on Twitter
Published on October 17, 2023 11:00

October 15, 2023

Benchmark Python Program with time Unix Command

You can benchmark Python programs without making any modifications to the code by using the time command. In this tutorial, you will discover how to benchmark Python programs using the time command. Let’s get started. Need to Benchmark Python Script Benchmarking Python code refers to comparing the performance of one program to variations of the […]
 •  0 comments  •  flag
Share on Twitter
Published on October 15, 2023 11:00

October 12, 2023

time.time() vs timeit in Python

You can use the time.time() function to access the system time. The timeit module can be used to benchmark ad hoc snippets of Python code. The time.time() function should probably no longer be used for benchmarking Python code because it uses a clock that is adjustable, non-monotonic, and low precision. Instead, the time.perf_counter() function can […]
 •  0 comments  •  flag
Share on Twitter
Published on October 12, 2023 11:00