Last active
August 29, 2015 14:01
-
-
Save up1/2e12846bc90afd5dd238 to your computer and use it in GitHub Desktop.
Go :: Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
func Fibonacci(number int) int { | |
if number < 2 { | |
return number | |
} | |
return Fibonacci(number-1) + Fibonacci(number-2) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
import "testing" | |
func BenchmarkFibonacci5(b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
Fibonacci(5) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
import "testing" | |
func benchmarkFibonacci(number int, b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
Fibonacci(number) | |
} | |
} | |
func BenchmarkFibonacci1(b *testing.B) { | |
benchmarkFibonacci(1, b) | |
} | |
func BenchmarkFibonacci3(b *testing.B) { | |
benchmarkFibonacci(3, b) | |
} | |
func BenchmarkFibonacci5(b *testing.B) { | |
benchmarkFibonacci(5, b) | |
} | |
func BenchmarkFibonacci7(b *testing.B) { | |
benchmarkFibonacci(7, b) | |
} | |
func BenchmarkFibonacci10(b *testing.B) { | |
benchmarkFibonacci(10, b) | |
} | |
func BenchmarkFibonacci20(b *testing.B) { | |
benchmarkFibonacci(20, b) | |
} | |
func BenchmarkFibonacci30(b *testing.B) { | |
benchmarkFibonacci(30, b) | |
} | |
func BenchmarkFibonacci40(b *testing.B) { | |
benchmarkFibonacci(40, b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment