shilangyu / scoop-search

Fast `scoop search` drop-in replacement 🚀
MIT License
289 stars 10 forks source link

Switch to faster printing #2

Closed shilangyu closed 4 years ago

shilangyu commented 4 years ago

By preparing the whole output and printing once with os.Stdout.Write

shilangyu commented 4 years ago

The final string is built with strings.Builder and then printed once with os.Stdout.Write.

Benchmarks

❯ 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'