countlines in go asm, v1
This commit is contained in:
commit
9384c46598
8 changed files with 250 additions and 0 deletions
61
benchmark_test.go
Normal file
61
benchmark_test.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package countlines
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type size struct {
|
||||
name string
|
||||
l int
|
||||
}
|
||||
|
||||
var sizes = []size{
|
||||
{"32", 32},
|
||||
{"128", 128},
|
||||
{"1K", 1 * 1024},
|
||||
{"16K", 16 * 1024},
|
||||
{"128K", 128 * 1024},
|
||||
{"1M", 1024 * 1024},
|
||||
{"16M", 16 * 1024 * 1024},
|
||||
{"128M", 128 * 1024 * 1024},
|
||||
{"512M", 512 * 1024 * 1024},
|
||||
}
|
||||
|
||||
func randRead64(s []uint64) {
|
||||
for i := range s {
|
||||
s[i] = uint64(rand.Int63())
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCountNewlines(b *testing.B) {
|
||||
for _, size := range sizes {
|
||||
b.Run(size.name, func(b *testing.B) {
|
||||
s := make([]byte, size.l)
|
||||
rand.Read(s)
|
||||
|
||||
b.SetBytes(int64(size.l))
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
CountNewlines(s)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCountNewlinesGo(b *testing.B) {
|
||||
for _, size := range sizes {
|
||||
b.Run(size.name, func(b *testing.B) {
|
||||
s := make([]byte, size.l)
|
||||
rand.Read(s)
|
||||
|
||||
b.SetBytes(int64(size.l))
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
countNewlinesGo(s)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue