pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/RustPython/RustPython/commit/763d5d48b57ee13bbefe9b9306d6f5db8deb69ee

css" /> Add sorted.py to microbenchmarks (#6086) · RustPython/RustPython@763d5d4 · GitHub
Skip to content

Commit 763d5d4

Browse files
Add sorted.py to microbenchmarks (#6086)
* 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. * Mention how to run a specific benchmark * Update python version in bench README 3.13 better reflects the current state of the project vs 3.7.
1 parent c6d1a57 commit 763d5d4

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

benches/README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,36 @@ These are some files to determine performance of rustpython.
44

55
## Usage
66

7-
Running `cargo bench` from the root of the repository will start the benchmarks. Once done there will be a graphical
7+
Running `cargo bench` from the root of the repository will start the benchmarks. Once done there will be a graphical
88
report under `target/criterion/report/index.html` that you can use use to view the results.
99

10-
To view Python tracebacks during benchmarks, run `RUST_BACKTRACE=1 cargo bench`. You can also bench against a
10+
`cargo bench` supports name matching to run a subset of the benchmarks. To
11+
run only the sorted microbenchmark, you can run:
12+
13+
```shell
14+
cargo bench sorted
15+
```
16+
17+
To view Python tracebacks during benchmarks, run `RUST_BACKTRACE=1 cargo bench`. You can also bench against a
1118
specific installed Python version by running:
1219

1320
```shell
14-
$ PYTHON_SYS_EXECUTABLE=python3.7 cargo bench
21+
PYTHON_SYS_EXECUTABLE=python3.13 cargo bench
1522
```
1623

1724
### Adding a benchmark
1825

19-
Simply adding a file to the `benchmarks/` directory will add it to the set of files benchmarked. Each file is tested
26+
Simply adding a file to the `benchmarks/` directory will add it to the set of files benchmarked. Each file is tested
2027
in two ways:
2128

2229
1. The time to parse the file to AST
2330
2. The time it takes to execute the file
2431

2532
### Adding a micro benchmark
2633

27-
Micro benchmarks are small snippets of code added under the `microbenchmarks/` directory. A microbenchmark file has
34+
Micro benchmarks are small snippets of code added under the `microbenchmarks/` directory. A microbenchmark file has
2835
two sections:
36+
2937
1. Optional setup code
3038
2. The code to be benchmarked
3139

@@ -39,8 +47,8 @@ a_list = [1,2,3]
3947
len(a_list)
4048
```
4149

42-
Only `len(a_list)` will be timed. Setup or benchmarked code can optionally reference a variable called `ITERATIONS`. If
43-
present then the benchmark code will be invoked 5 times with `ITERATIONS` set to a value between 100 and 1,000. For
50+
Only `len(a_list)` will be timed. Setup or benchmarked code can optionally reference a variable called `ITERATIONS`. If
51+
present then the benchmark code will be invoked 5 times with `ITERATIONS` set to a value between 100 and 1,000. For
4452
example:
4553

4654
```python
@@ -49,7 +57,7 @@ obj = [i for i in range(ITERATIONS)]
4957

5058
`ITERATIONS` can appear in both the setup code and the benchmark code.
5159

52-
## MacOS setup
60+
## MacOS setup
5361

5462
On MacOS you will need to add the following to a `.cargo/config` file:
5563

@@ -63,4 +71,4 @@ rustflags = [
6371

6472
## Benchmark source
6573

66-
- https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-python3-2.html
74+
- <https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-python3-2.html>

benches/microbenchmarks/sorted.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from random import random, seed
2+
seed(0)
3+
4+
unsorted_list = [random() for _ in range(5 * ITERATIONS)]
5+
6+
# ---
7+
8+
# Setup code only runs once so do not modify in-place
9+
sorted(unsorted_list)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy