-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
88 lines (77 loc) · 1.49 KB
/
benchmark_test.go
File metadata and controls
88 lines (77 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//go:build wasm
package jsvalue
import (
"syscall/js"
"testing"
)
// Prevent compiler optimizations
var (
resJS js.Value
resErr error
)
func BenchmarkToJS_Int(b *testing.B) {
input := 12345
b.ResetTimer()
for i := 0; i < b.N; i++ {
resJS = ToJS(input)
}
}
func BenchmarkToJS_String(b *testing.B) {
input := "hello world"
b.ResetTimer()
for i := 0; i < b.N; i++ {
resJS = ToJS(input)
}
}
func BenchmarkToJS_Struct(b *testing.B) {
input := TestStruct{Name: "Alice", Age: 30}
b.ResetTimer()
for i := 0; i < b.N; i++ {
resJS = ToJS(input)
}
}
func BenchmarkToGo_Int(b *testing.B) {
val := ToJS(12345)
var out int
b.ResetTimer()
for i := 0; i < b.N; i++ {
resErr = ToGo(val, &out)
}
}
func BenchmarkToGo_Struct(b *testing.B) {
input := TestStruct{Name: "Alice", Age: 30}
val := ToJS(input)
var out TestStruct
b.ResetTimer()
for i := 0; i < b.N; i++ {
resErr = ToGo(val, &out)
}
}
func BenchmarkToGo_Any_Int(b *testing.B) {
val := ToJS(12345)
b.ResetTimer()
for i := 0; i < b.N; i++ {
// New API requires dest
var out any
resErr = ToGo(val, &out)
}
}
func BenchmarkToGo_Any_Map(b *testing.B) {
input := map[string]any{"a": 1, "b": "c"}
val := ToJS(input)
b.ResetTimer()
for i := 0; i < b.N; i++ {
// New API
var out any
resErr = ToGo(val, &out)
}
}
func BenchmarkToGo_Map_Reuse(b *testing.B) {
input := map[string]any{"a": 1, "b": "c"}
val := ToJS(input)
var out map[string]any
b.ResetTimer()
for i := 0; i < b.N; i++ {
resErr = ToGo(val, &out)
}
}