/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks * License: LLVM Release License. See Notice file */ package org.linaro.benchmarks.stanford; import org.openjdk.jmh.annotations.*; import java.util.concurrent.TimeUnit; @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) @State(Scope.Benchmark) public class Perm { private static final int permrange = 10; private boolean error; /* Perm */ private int[] permarray = new int [permrange + 1]; /* converted pctr to unsigned int for 16 bit WR*/ private int pctr; // CHECKSTYLE.OFF: .* /* Permutation program, heavily recursive, written by Denny Brown. */ void Swap ( int a[], int ai, int b[], int bi ) { int t; t = a[ai]; a[ai] = b[bi]; b[bi] = t; } void Initialize () { int i; for ( i = 1; i <= 7; i++ ) { permarray[i]=i-1; } } void Permute (int n) { /* permute */ int k; pctr = pctr + 1; if ( n!=1 ) { Permute(n-1); for ( k = n-1; k >= 1; k-- ) { Swap(permarray, n, permarray, k); Permute(n-1); Swap(permarray, n, permarray, k); } } } /* permute */ void Perm () { /* Perm */ int i; pctr = 0; for ( i = 1; i <= 5; i++ ) { Initialize(); Permute(7); } if ( pctr != 43300 ) error = true; } /* Perm */ // CHECKSTYLE.ON: .* @Benchmark public void jmhTimePerm() { Perm(); } }