This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
bench_test.go
71 lines (64 loc) · 1.54 KB
/
bench_test.go
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
package main
import "testing"
import "github.com/stretchr/testify/assert"
import . "github.com/hraberg/cljs2go/cljs/core"
func Benchmark_RecursiveDirectCall(t *testing.B) {
fib := func(this *AFn) *AFn {
return Fn(this, func(n interface{}) interface{} {
if n == 0.0 {
return 0.0
} else if n == 1.0 {
return 1.0
} else {
return this.X_invoke_Arity1(n.(float64)-1.0).(float64) +
this.X_invoke_Arity1(n.(float64)-2.0).(float64)
}
})
}(&AFn{})
assert.Equal(t, 832040, fib.X_invoke_Arity1(30.0))
}
func Benchmark_RecursiveDirectPrimitiveCall(t *testing.B) {
fib := func(this *AFn) *AFn {
return Fn(this, func(n float64) float64 {
if n == 0.0 {
return 0.0
} else if n == 1.0 {
return 1.0
} else {
return this.Arity1FF(n-1.0) + this.Arity1FF(n-2.0)
}
})
}(&AFn{})
assert.Equal(t, 832040, fib.X_invoke_Arity1(30.0))
}
func Benchmark_RecursiveDispatch(t *testing.B) {
fib := func(this *AFn) *AFn {
return Fn(this, func(a interface{}) interface{} {
var n = a.(float64)
if n == 0.0 {
return 0.0
} else if n == 1.0 {
return 1.0
} else {
return this.Call(n-1.0).(float64) + this.Call(n-2.0).(float64)
}
})
}(&AFn{})
assert.Equal(t, 832040, fib.Call(30.0))
}
func Benchmark_RecursiveGo(t *testing.B) {
fib := func() func(float64) float64 {
var this func(float64) float64
this = func(n float64) float64 {
if n == 0 {
return 0
} else if n == 1 {
return 1
} else {
return this(n-1) + this(n-2)
}
}
return this
}()
assert.Equal(t, 832040, fib(30))
}