Исходники и презентации
This commit is contained in:
27
lessons/strings/range_ascii_vs_utf8/speed_test.go
Normal file
27
lessons/strings/range_ascii_vs_utf8/speed_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// go test -bench=. speed_test.go
|
||||
|
||||
func BenchmarkByRangeBytes(b *testing.B) {
|
||||
text := []byte("aaaabbbbccccddddeeeeffff")
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, _ = range text {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkByRangeStringUTF8(b *testing.B) {
|
||||
text := "aaaabbbbccccddddeeeeffff"
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, _ = range text {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user