iteration: Use strings pkg and compare the bench results

This commit is contained in:
vinchent 2024-09-10 13:39:14 +02:00
parent 75304d4c23
commit fb1e5e2835

View File

@ -1,10 +1,16 @@
package iteration
import "strings"
// Repeat takes a string and repeat it 5 times
func Repeat(s string, repeatTime int) string {
var res string
for i := 0; i < repeatTime; i++ {
res += s
}
return res
// // Bench: 170ns
// var res string
// for i := 0; i < repeatTime; i++ {
// res += s
// }
// return res
// Bench: 70ns
return strings.Repeat(s, repeatTime)
}