From 338b462373bbc18fbce99d14b4211067c309f649 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Sat, 9 Aug 2025 22:07:28 +0100 Subject: [PATCH 1/2] Add microbenchmark for `sorted` I chose 5 * Iterations to try better show that RustPython sort implementation scales noticeably worse CPython's with respect to the number of elements. --- benches/microbenchmarks/sort.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 benches/microbenchmarks/sort.py diff --git a/benches/microbenchmarks/sort.py b/benches/microbenchmarks/sort.py new file mode 100644 index 0000000000..62a2d71e13 --- /dev/null +++ b/benches/microbenchmarks/sort.py @@ -0,0 +1,7 @@ +from random import random + +unsorted_list = [random() for _ in range(5 * ITERATIONS)] + +# --- + +unsorted_list.sort() From 5531ae2b08c6b4a45a7c49236420735e5c41702b Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Sat, 9 Aug 2025 22:57:17 +0100 Subject: [PATCH 2/2] Mention how to run a specific benchmark --- benches/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/benches/README.md b/benches/README.md index f6e5129617..b20079ba25 100644 --- a/benches/README.md +++ b/benches/README.md @@ -7,7 +7,14 @@ These are some files to determine performance of rustpython. Running `cargo bench` from the root of the repository will start the benchmarks. Once done there will be a graphical report under `target/criterion/report/index.html` that you can use use to view the results. -To view Python tracebacks during benchmarks, run `RUST_BACKTRACE=1 cargo bench`. You can also bench against a +`cargo bench` supports name matching to run a subset of the benchmarks. To +run only the sort microbenchmark, you can run: + +```shell +cargo bench sort +``` + +To view Python tracebacks during benchmarks, run `RUST_BACKTRACE=1 cargo bench`. You can also bench against a specific installed Python version by running: ```shell