Skip to content

Commit

Permalink
refactor: Use shortest possible name for benchmarks
Browse files Browse the repository at this point in the history
Strip 2x `bench_` from benchmark names. Just feels cleaner.
  • Loading branch information
ankush committed Dec 26, 2024
1 parent a4c6bd7 commit f77bb91
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions caffeine/microbenchmarks/run_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,22 @@ def discover_benchmarks(benchmark_filter):
bench_qb,
]

all_benchmarks = set()
benchmarks = []
for module in benchmark_modules:
module_name = module.__name__.split(".")[-1]
module_name = module.__name__.split(".")[-1].removeprefix(BENCHMARK_PREFIX)
for bench_name, bench in inspect.getmembers(
module, predicate=lambda x: isinstance(x, FunctionType | NanoBenchmark)
):
if bench_name.startswith(BENCHMARK_PREFIX):
unique_name = f"{module_name}_{bench_name}"
if benchmark_filter in unique_name:
benchmarks.append((unique_name, bench))
bench_name = module_name + "_" + bench_name.removeprefix(BENCHMARK_PREFIX)
if bench_name in all_benchmarks:
frappe.throw(
f"Another benchmark with same name exists: `{bench_name}`. Please rename the benchmark."
)
all_benchmarks.add(bench_name)
if benchmark_filter in bench_name:
benchmarks.append((bench_name, bench))

return sorted(benchmarks, key=lambda x: x[0])

Expand Down

0 comments on commit f77bb91

Please sign in to comment.