MCPcopy Index your code
hub / github.com/Shopify/go-lua / BenchmarkFibonnaci

Function BenchmarkFibonnaci

vm_test.go:142–167  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

140}
141
142func BenchmarkFibonnaci(b *testing.B) {
143 l := NewState()
144 s := `return function(n)
145 if n == 0 then
146 return 0
147 elseif n == 1 then
148 return 1
149 end
150 local n0, n1 = 0, 1
151 for i = n, 2, -1 do
152 local tmp = n0 + n1
153 n0 = n1
154 n1 = tmp
155 end
156 return n1
157 end`
158 LoadString(l, s)
159 if err := l.ProtectedCall(0, 1, 0); err != nil {
160 b.Error(err.Error())
161 }
162 l.PushInteger(b.N)
163 b.ResetTimer()
164 if err := l.ProtectedCall(1, 1, 0); err != nil {
165 b.Error(err.Error())
166 }
167}
168
169// TestTailCallRecursive tests for failures where both the callee and caller are making a tailcall.
170func TestTailCallRecursive(t *testing.T) {

Callers

nothing calls this directly

Calls 5

ProtectedCallMethod · 0.95
PushIntegerMethod · 0.95
NewStateFunction · 0.85
LoadStringFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected