2026-06-08 20:47:30 +08:00
|
|
|
package js
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func BenchmarkCall(b *testing.B) {
|
|
|
|
|
p := NewPool()
|
|
|
|
|
p.Define(`function add(a, b) { return a + b; }`)
|
|
|
|
|
args := []any{1, 2}
|
|
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2026-06-10 10:45:33 +08:00
|
|
|
_, err := p.Call("add", 0, nil, args...)
|
2026-06-08 20:47:30 +08:00
|
|
|
if err != nil {
|
|
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkSync(b *testing.B) {
|
|
|
|
|
p := NewPool()
|
|
|
|
|
code := `function f() { return 1; }`
|
2026-06-10 10:45:33 +08:00
|
|
|
|
2026-06-08 20:47:30 +08:00
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
p.Define(code)
|
2026-06-10 10:45:33 +08:00
|
|
|
_, err := p.Call("f", 0, nil)
|
2026-06-08 20:47:30 +08:00
|
|
|
if err != nil {
|
|
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|