mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-07 23:07:14 +02:00
Implements std.reverse in native Go, improving performance benchmark old ns/op new ns/op delta Benchmark_Builtin_reverse-16 869191619 231309458 -73.39% part of #111
41 lines
764 B
Go
41 lines
764 B
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")
|
|
}
|