go_goja_gopherlua_benchmark/goja_bench_test.go
2024-03-09 10:01:17 +03:30

24 lines
473 B
Go

package main
import (
"testing"
"github.com/dop251/goja"
)
func BenchmarkGojaNumericalCalculation(b *testing.B) {
vm := goja.New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
vm.RunString("let sum = 0; for (let i = 1; i <= 1000000; i++) { sum += i; }")
}
}
func BenchmarkGojaStringManipulation(b *testing.B) {
vm := goja.New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
vm.RunString(`let result = ""; for (let i = 0; i < 10000; i++) { result += "a"; }`)
}
}