1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This benchmark, taken from the shootout, tests array indexing
6 // and array bounds elimination performance.
12 func fannkuch(n int) int {
18 perm := make([]int, n)
19 perm1 := make([]int, n)
20 count := make([]int, n)
22 for i := 0; i < n; i++ {
23 perm1[i] = i // initial (trivial) permutation
37 if perm1[0] != 0 && perm1[n1] != n1 {
39 for i := 1; i < n; i++ { // perm = perm1
42 k := perm1[0] // cache perm[0] in k
44 for i, j := 1, k-1; i < j; i, j = i+1, j-1 {
45 perm[i], perm[j] = perm[j], perm[i]
48 // Now exchange k (caching perm[0]) and perm[k]... with care!
62 // rotate down perm[0..r] by one
64 for i := 0; i < r; i++ {
80 func BenchmarkFannkuch11(b *testing.B) {
81 for i := 0; i < b.N; i++ {