mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-11 00:37:12 +02:00
feat: improve std.base64Decode performance 97%+ Provides a Go-native implementation of std.base64Decode and std.base64DecodeBytes benchmark old ns/op new ns/op delta Benchmark_Builtin_base64Decode-16 10946388307 25004135 -99.77% Benchmark_Builtin_base64DecodeBytes-16 6420742757 181513016 -97.17% related to #111
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package jsonnet
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"testing"
|
|
)
|
|
|
|
var jsonnetPath string
|
|
var outputPassthru bool
|
|
|
|
func init() {
|
|
flag.StringVar(&jsonnetPath, "jsonnetPath", "./jsonnet", "Path to jsonnet binary")
|
|
flag.BoolVar(&outputPassthru, "outputPassthru", false, "Pass stdout/err from jsonnet")
|
|
}
|
|
|
|
func RunBenchmark(b *testing.B, name string) {
|
|
for n := 0; n < b.N; n++ {
|
|
cmd := exec.Command(jsonnetPath, fmt.Sprintf("./builtin-benchmarks/%s.jsonnet", name))
|
|
if outputPassthru {
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
}
|
|
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
b.Fail()
|
|
}
|
|
}
|
|
}
|
|
|
|
func Benchmark_Builtin_substr(b *testing.B) {
|
|
RunBenchmark(b, "substr")
|
|
}
|
|
|
|
func Benchmark_Builtin_reverse(b *testing.B) {
|
|
RunBenchmark(b, "reverse")
|
|
}
|
|
|
|
func Benchmark_Builtin_base64Decode(b *testing.B) {
|
|
RunBenchmark(b, "base64Decode")
|
|
}
|
|
|
|
func Benchmark_Builtin_base64DecodeBytes(b *testing.B) {
|
|
RunBenchmark(b, "base64DecodeBytes")
|
|
}
|
|
|
|
func Benchmark_Builtin_base64(b *testing.B) {
|
|
RunBenchmark(b, "base64")
|
|
}
|
|
|
|
func Benchmark_Builtin_base64_byte_array(b *testing.B) {
|
|
RunBenchmark(b, "base64_byte_array")
|
|
}
|