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.
Sprintf
andPrintf
are slower thanSprint
andPrint
. And if there is no format argument, it is redundant to use format functions. Socolor
works now faster and consumes less memory:Also, I renamed
printColor
andprintString
tocolorPrint
andcolorString
respectively. I think, it's clearer now what do these functions, becauseprintString
doesn't actually print.