Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commented Oct 10, 2024

@vstinner
Copy link
MemberAuthor

vstinner commented Oct 10, 2024

Benchmark:

importpyperfrunner=pyperf.Runner() runner.bench_func('repr({})', repr,{}) runner.bench_func("repr({'a': 'A'})", repr,{'a': 'A'}) runner.bench_func("repr({'a': 'A', ...})", repr,{'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E'}) runner.bench_func("repr({'a': 1})", repr,{'a': 1}) runner.bench_func("repr({'a': 1, ...})", repr,{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5})

Results, Python built with gcc -O3, CPU isolation, --rigorous:

+-----------------------+--------+----------------------+ | Benchmark | ref | change | +=======================+========+======================+ | repr({}) | 106 ns | 107 ns: 1.01x slower | +1 ns +-----------------------+--------+----------------------+ | repr({'a': 'A'}) | 260 ns | 255 ns: 1.02x faster | -5 ns +-----------------------+--------+----------------------+ | repr({'a': 'A', ...}) | 717 ns | 728 ns: 1.01x slower | +11 ns +-----------------------+--------+----------------------+ | repr({'a': 1, ...}) | 802 ns | 755 ns: 1.06x faster | -47 ns +-----------------------+--------+----------------------+ | Geometric mean | (ref) | 1.01x faster | +-----------------------+--------+----------------------+ Benchmark hidden because not significant (1): repr({'a': 1}) 

There is basically no significan effect on performance. Only repr({'a': 1, ...}) is a little bit faster thanks to the integer fast-path.

UPDATE: I reran benchmarks with --rigorous.

@vstinnervstinner merged commit bb594e8 into python:mainOct 10, 2024
@vstinnervstinner deleted the writer_dict branch October 10, 2024 18:41
@vstinner
Copy link
MemberAuthor

Merged, thanks for the review @methane.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@methane