iteration: Use strings pkg and compare the bench results
This commit is contained in:
parent
75304d4c23
commit
fb1e5e2835
@ -1,10 +1,16 @@
|
|||||||
package iteration
|
package iteration
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
// Repeat takes a string and repeat it 5 times
|
// Repeat takes a string and repeat it 5 times
|
||||||
func Repeat(s string, repeatTime int) string {
|
func Repeat(s string, repeatTime int) string {
|
||||||
var res string
|
// // Bench: 170ns
|
||||||
for i := 0; i < repeatTime; i++ {
|
// var res string
|
||||||
res += s
|
// for i := 0; i < repeatTime; i++ {
|
||||||
}
|
// res += s
|
||||||
return res
|
// }
|
||||||
|
// return res
|
||||||
|
|
||||||
|
// Bench: 70ns
|
||||||
|
return strings.Repeat(s, repeatTime)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user