Skip to content

Instantly share code, notes, and snippets.

@andizzle
Created September 28, 2017 12:01
Show Gist options
  • Save andizzle/8f74c3fc88844c659a505bd52c83c521 to your computer and use it in GitHub Desktop.
Save andizzle/8f74c3fc88844c659a505bd52c83c521 to your computer and use it in GitHub Desktop.
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]
}
}
}
@andizzle
Copy link
Author

andizzle commented Sep 28, 2017

go test -run=1 -bench=.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment