109 lines
3.3 KiB
Go
109 lines
3.3 KiB
Go
// SPDX-License-Identifier: Unlicense
|
|
|
|
package naive_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.codemonkeysoftware.net/b/gigaparsec"
|
|
"git.codemonkeysoftware.net/b/gigaparsec/naive"
|
|
)
|
|
|
|
func BenchmarkBind5(b *testing.B) {
|
|
type Bind5T = func(p gigaparsec.Parser[byte, byte], f func(byte) gigaparsec.Parser[byte, byte], f2 func(byte) gigaparsec.Parser[byte, byte], f3 func(byte) gigaparsec.Parser[byte, byte], f4 func(byte) gigaparsec.Parser[byte, byte], f5 func(byte) gigaparsec.Parser[byte, byte]) gigaparsec.Parser[byte, byte]
|
|
|
|
f := func(b byte) gigaparsec.Parser[byte, byte] {
|
|
return gigaparsec.Return[byte](b + 1)
|
|
}
|
|
p := func(bind5 Bind5T) gigaparsec.Parser[byte, byte] {
|
|
// gigaparsec.Bind5()
|
|
return bind5(gigaparsec.Match(byte(0)), f, f, f, f, f)
|
|
}
|
|
input := gigaparsec.SliceReaderAt[byte]{0}
|
|
b.Run("gigaparsec.Bind5", func(b *testing.B) {
|
|
for range b.N {
|
|
gigaparsec.Run(p(gigaparsec.Bind5), input)
|
|
}
|
|
|
|
})
|
|
b.Run("naïve.Bind5", func(b *testing.B) {
|
|
for range b.N {
|
|
gigaparsec.Run(p(naive.Bind5), input)
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkBind9(b *testing.B) {
|
|
type Bind9T = func(p gigaparsec.Parser[byte, byte], f func(byte) gigaparsec.Parser[byte, byte], f2 func(byte) gigaparsec.Parser[byte, byte], f3 func(byte) gigaparsec.Parser[byte, byte], f4 func(byte) gigaparsec.Parser[byte, byte], f5 func(byte) gigaparsec.Parser[byte, byte], f6 func(byte) gigaparsec.Parser[byte, byte], f7 func(byte) gigaparsec.Parser[byte, byte], f8 func(byte) gigaparsec.Parser[byte, byte], f9 func(byte) gigaparsec.Parser[byte, byte]) gigaparsec.Parser[byte, byte]
|
|
|
|
f := func(b byte) gigaparsec.Parser[byte, byte] {
|
|
return gigaparsec.Return[byte](b + 1)
|
|
}
|
|
p := func(bind5 Bind9T) gigaparsec.Parser[byte, byte] {
|
|
// gigaparsec.Bind5()
|
|
return bind5(gigaparsec.Match(byte(0)), f, f, f, f, f, f, f, f, f)
|
|
}
|
|
input := gigaparsec.SliceReaderAt[byte]{0}
|
|
b.Run("gigaparsec.Bind9", func(b *testing.B) {
|
|
for range b.N {
|
|
gigaparsec.Run(p(gigaparsec.Bind9), input)
|
|
}
|
|
|
|
})
|
|
b.Run("naive.Bind9", func(b *testing.B) {
|
|
for range b.N {
|
|
gigaparsec.Run(p(naive.Bind9), input)
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkSeq5(b *testing.B) {
|
|
type P = gigaparsec.Parser[byte, byte]
|
|
type Seq5T = func(P, P, P, P, P, func(byte, byte, byte, byte, byte) byte) P
|
|
|
|
zero := gigaparsec.Return[byte, byte](0)
|
|
|
|
f := func(a, b, c, d, e byte) byte {
|
|
return a + b + c + d + e
|
|
}
|
|
p := func(seq5 Seq5T) P {
|
|
return seq5(zero, zero, zero, zero, zero, f)
|
|
}
|
|
input := gigaparsec.SliceReaderAt[byte]{0}
|
|
b.Run("gigaparsec.Seq5", func(b *testing.B) {
|
|
for range b.N {
|
|
gigaparsec.Run(p(gigaparsec.Seq5), input)
|
|
}
|
|
})
|
|
b.Run("naive.Seq5", func(b *testing.B) {
|
|
for range b.N {
|
|
gigaparsec.Run(p(naive.Seq5), input)
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkSeq9(b *testing.B) {
|
|
type P = gigaparsec.Parser[byte, byte]
|
|
type Seq9T = func(P, P, P, P, P, P, P, P, P, func(byte, byte, byte, byte, byte, byte, byte, byte, byte) byte) P
|
|
|
|
zero := gigaparsec.Return[byte, byte](0)
|
|
|
|
f := func(a, b, c, d, e, f, g, h, i byte) byte {
|
|
return a + b + c + d + e + f + g + h + i
|
|
}
|
|
p := func(seq9 Seq9T) P {
|
|
return seq9(zero, zero, zero, zero, zero, zero, zero, zero, zero, f)
|
|
}
|
|
input := gigaparsec.SliceReaderAt[byte]{0}
|
|
b.Run("gigaparsec.Seq9", func(b *testing.B) {
|
|
for range b.N {
|
|
gigaparsec.Run(p(gigaparsec.Seq9), input)
|
|
}
|
|
})
|
|
b.Run("naive.Seq9", func(b *testing.B) {
|
|
for range b.N {
|
|
gigaparsec.Run(p(naive.Seq9), input)
|
|
}
|
|
})
|
|
}
|