Closed shilangyu closed 4 years ago
The final string is built with strings.Builder
and then printed once with os.Stdout.Write
.
❯ hyperfine --show-output '.\fmt.exe' '.\string-builder.exe'
# a lot of output later
Summary
'.\string-builder.exe' ran
1.45 ± 0.04 times faster than '.\fmt.exe'
So 45% speedup in best case scenario (printing all existing manifests). On a search with little results the speed gain is less noticeable:
❯ hyperfine --show-output '.\fmt.exe google' '.\string-builder.exe google'
# a lot of output later
Summary
'.\string-builder.exe google' ran
1.02 ± 0.04 times faster than '.\fmt.exe google'
By preparing the whole output and printing once with
os.Stdout.Write