Skip to content
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

Get rid of the use of str.repeat() #24

Merged
merged 1 commit into from
Jan 10, 2019
Merged

Conversation

lilyball
Copy link
Contributor

This allocates a string. Instead we can (ab)use format specifiers to do the repetitions for us.

This produces a very mild speedup:

Benchmark #1: ./original_hexyl original_hexyl
  Time (mean ± σ):      1.482 s ±  0.016 s    [User: 1.426 s, System: 0.050 s]
  Range (min … max):    1.468 s …  1.516 s
 
Benchmark #2: ./target/release/hexyl original_hexyl
  Time (mean ± σ):      1.473 s ±  0.002 s    [User: 1.423 s, System: 0.046 s]
  Range (min … max):    1.472 s …  1.480 s
 
Summary
  './target/release/hexyl original_hexyl' ran
    1.01 ± 0.01 times faster than './original_hexyl original_hexyl'

This allocates a string. Instead we can (ab)use format specifiers to do
the repetitions for us.
@sharkdp
Copy link
Owner

sharkdp commented Jan 10, 2019

That's pretty cool! Thank you very much.

@sharkdp sharkdp merged commit 7b7a0ff into sharkdp:master Jan 10, 2019
@lilyball lilyball deleted the remove_repeat branch January 10, 2019 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants