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

Make indent faster by preallocating the output string #354

Merged
merged 2 commits into from
May 13, 2021

Conversation

mgeisler
Copy link
Owner

@mgeisler mgeisler commented May 13, 2021

On my system, it took just under 2 microseconds to indent a ~2 KB text with 50 lines:

% cargo criterion --bench indent
indent                  time:   [1.8829 us 1.8891 us 1.8948 us]

Preallocating the output string makes the function about 20% faster:

% cargo criterion --bench indent
indent                  time:   [1.4647 us 1.4670 us 1.4698 us]
                        change: [-23.426% -22.816% -22.328%] (p = 0.00 < 0.05)
                        Performance has improved.

On my system, it takes just under 2 microseconds to indent the 50
lines in the ~2 KB text:

    % cargo criterion --bench indent
    indent                  time:   [1.8829 us 1.8891 us 1.8948 us]
@mgeisler mgeisler enabled auto-merge May 13, 2021 12:05
@mgeisler mgeisler disabled auto-merge May 13, 2021 12:07
@mgeisler mgeisler changed the title Add simple benchmark for indent Preallocate output string for indent May 13, 2021
This makes the function about 20% faster:

    % cargo criterion --bench indent
    indent                  time:   [1.4647 us 1.4670 us 1.4698 us]
                            change: [-23.426% -22.816% -22.328%] (p = 0.00 < 0.05)
                            Performance has improved.
@mgeisler mgeisler changed the title Preallocate output string for indent Make indent faster by preallocating the output string May 13, 2021
@mgeisler mgeisler enabled auto-merge May 13, 2021 12:38
@mgeisler mgeisler merged commit e505b89 into master May 13, 2021
@mgeisler mgeisler deleted the indent-benchmark branch May 13, 2021 12:39
This was referenced May 30, 2021
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.

1 participant