-
Notifications
You must be signed in to change notification settings - Fork 2
/
fib_test.go
31 lines (26 loc) · 873 Bytes
/
fib_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
package main
import "testing"
// func benchmarkFib(i int, b *testing.B) {
// // run the Fib function b.N times
// for n := 0; n < b.N; n++ {
// Fib(i)
// }
// }
// func BenchmarkFib1(b *testing.B) { benchmarkFib(1, b) }
// func BenchmarkFib2(b *testing.B) { benchmarkFib(2, b) }
// func BenchmarkFib3(b *testing.B) { benchmarkFib(3, b) }
// func BenchmarkFib10(b *testing.B) { benchmarkFib(10, b) }
// func BenchmarkFib20(b *testing.B) { benchmarkFib(20, b) }
// func BenchmarkFib40(b *testing.B) { benchmarkFib(40, b) }
var result int
func BenchmarkFibComplete(b *testing.B) {
var r int
for n := 0; n < b.N; n++ {
// always record the result of Fib to prevent
// the compiler eliminating the function call.
r = Fib(10)
}
// always store the result to a package level variable
// so the compiler cannot eliminate the Benchmark itself.
result = r
}