Исходники и презентации

This commit is contained in:
2025-05-23 07:26:39 +03:00
parent aa948179d5
commit 02d8430a3a
514 changed files with 13773 additions and 0 deletions

View File

@ -0,0 +1,45 @@
package main
import (
"fmt"
"strings"
"testing"
)
// go test -bench=. concatenation_test.go
func BenchmarkConcatenationWithSprintf(b *testing.B) {
s0 := "str1"
s1 := "str2"
s2 := "str3"
s3 := "str4"
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = fmt.Sprintf("%s%s%s%s", s0, s1, s2, s3)
}
}
func BenchmarkConcatenationWithOperatorPlus(b *testing.B) {
s0 := "str1"
s1 := "str2"
s2 := "str3"
s3 := "str4"
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = s0 + s1 + s2 + s3
}
}
func BenchmarkConcatenationWithJoin(b *testing.B) {
s0 := "str1"
s1 := "str2"
s2 := "str3"
s3 := "str4"
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = strings.Join([]string{s0, s1, s2, s3}, "")
}
}