| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Move tests on the separator outside the loop. Add a loop version for empty separator.
|
Benchmark: import pyperf
runner = pyperf.Runner()
for sep in ('', '.'):
for list_size in ('10', '10**3', '10**6'):
runner.timeit(
f'sep {sep!r}, {list_size} short items',
setup=f"data=['x']*{list_size}; sep={sep!r}",
stmt="sep.join(data)")
for list_size in ('10', '10**2', '10**4'):
runner.timeit(
f'sep {sep!r}, {list_size} long items',
setup=f"data=['x' * 100]*{list_size}; sep={sep!r}",
stmt="sep.join(data)")Results on Fedora 44 with CPU isolation:
Benchmark hidden because not significant (4): sep '', 10**4 long items, sep '.', 10**3 short items, sep '.', 10**6 short items, sep '.', 10**4 long items |
Sorry, something went wrong.
|
See also #158689 which optimizes bytes.join(). |
Sorry, something went wrong.
There was a problem hiding this comment.
The gain performance gain is only a bit and involves some code duplication. Have you benchmarked the two changes individually (e.g. unrolling the loop and making a fast path for the empty sep)?
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Move tests on the separator outside the loop. Add a loop version for empty separator.