8000 gh-108303: Move `Lib/test/sortperf.py` to `Tools/scripts` by sobolevn · Pull Request #114687 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-108303: Move Lib/test/sortperf.py to Tools/scripts #114687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address review
  • Loading branch information
sobolevn committed Feb 15, 2024
commit 7c2dd81535c67477188e9adf157f5fe158023ac8
20 changes: 11 additions & 9 deletions Tools/scripts/sortperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,12 @@ def run(self, loops: int) -> float:

def _prepare_data(self, loops: int) -> list[float]:
bench = BENCHMARKS[self._name]
return [
bench(self._size, self._random)
for _ in range(loops)
]
return [bench(self._size, self._random)] * loops


def add_cmdline_args(cmd: list[str], args) -> None:
cmd.append(args.benchmark)
if args.benchmark:
cmd.append(args.benchmark)
cmd.append(f"--size={args.size}")
cmd.append(f"--rng-seed={args.rng_seed}")

Expand All @@ -147,7 +145,6 @@ def add_parser_args(parser: argparse.ArgumentParser) -> None:
"benchmark",
choices=BENCHMARKS,
nargs="?",
default="list_sort",
help="Can be any of: {0}".format(", ".join(BENCHMARKS)),
)
parser.add_argument(
Expand All @@ -164,7 +161,7 @@ def add_parser_args(parser: argparse.ArgumentParser) -> None:
)


DEFAULT_SIZE = 262144 # 1 << 18
DEFAULT_SIZE = 1 << 14
DEFAULT_RANDOM_SEED = 0
BENCHMARKS = {
"list_sort": list_sort,
Expand All @@ -190,5 +187,10 @@ def add_parser_args(parser: argparse.ArgumentParser) -> None:
runner.metadata["list_sort_size"] = args.size
runner.metadata["list_sort_random_seed"] = args.rng_seed

benchmark = Benchmark(args.benchmark, args.size, args.rng_seed)
runner.bench_time_func(args.benchmark, benchmark.run)
if args.benchmark:
benchmarks = (args.benchmark,)
else:
benchmarks = sorted(BENCHMARKS)
for bench in benchmarks:
benchmark = Benchmark(bench, args.size, args.rng_seed)
runner.bench_time_func(bench, benchmark.run)
0