fatih / color

Color package for Go (golang)
https://pkg.go.dev/github.com/fatih/color
MIT License
7.26k stars 615 forks source link

Use print functions if there is no format #46

Closed n10v closed 7 years ago

n10v commented 7 years ago

Sprintf and Printf are slower than Sprint and Print. And if there is no format argument, it is redundant to use format functions. So color works now faster and consumes less memory:

benchmark                     old ns/op     new ns/op     delta
BenchmarkPrintNoFormat-4      6892          6768          -1.80%
BenchmarkStringNoFormat-4     1362          1345          -1.25%

benchmark                     old allocs     new allocs     delta
BenchmarkPrintNoFormat-4      10             9              -10.00%
BenchmarkStringNoFormat-4     13             13             +0.00%

benchmark                     old bytes     new bytes     delta
BenchmarkPrintNoFormat-4      120           104           -13.33%
BenchmarkStringNoFormat-4     152           152           +0.00%

Also, I renamed printColor and printString to colorPrint and colorString respectively. I think, it's clearer now what do these functions, because printString doesn't actually print.

fatih commented 7 years ago

Thanks @bogem