Skip to content

Make indent faster by preallocating the output string#354

Merged
mgeisler merged 2 commits intomasterfrom
indent-benchmark
May 13, 2021
Merged

Make indent faster by preallocating the output string#354
mgeisler merged 2 commits intomasterfrom
indent-benchmark

Conversation

@mgeisler
Copy link
Copy Markdown
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 force-pushed the indent-benchmark branch from 26f7857 to 19bb2ef Compare May 13, 2021 12:36
@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