Created
September 28, 2017 12:01
-
-
Save andizzle/8f74c3fc88844c659a505bd52c83c521 to your computer and use it in GitHub Desktop.
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 main | |
import ( | |
"strings" | |
"testing" | |
) | |
func BenchmarkFib10(b *testing.B) { | |
// run the Fib function b.N times | |
var c = "abcdefghijklmnopqrstuvwxyz" | |
c = strings.Repeat(c, 100000000) | |
a := []byte(c) | |
for n := 0; n < b.N; n++ { | |
for i := len(a)/2 - 1; i >= 0; i-- { | |
opp := len(a) - 1 - i | |
c := a[opp] | |
a[opp] = a[i] | |
a[i] = c | |
} | |
} | |
} | |
func BenchmarkFib11(b *testing.B) { | |
// run the Fib function b.N times | |
var c = "abcdefghijklmnopqrstuvwxyz" | |
c = strings.Repeat(c, 100000000) | |
a := []byte(c) | |
for n := 0; n < b.N; n++ { | |
for i := len(a)/2 - 1; i >= 0; i-- { | |
opp := len(a) - 1 - i | |
a[i], a[opp] = a[opp], a[i] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go test -run=1 -bench=.