summaryrefslogtreecommitdiff
path: root/BenchmarkFramework/app/src/main/java/art_benchmarks/stanford/Perm.java
blob: 99662082500a37bdb6d5fcd16e06f304f9cdce4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copied from https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_14/SingleSource/Benchmarks
 * License: LLVM Release License. See Notice file
 */

package art_benchmarks.stanford;

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: .*

  public void timePerm(int iters) {
    for (int i = 0; i < iters; i++) {
      Perm();
    }
  }

  public static boolean verify_Perm() {
    Perm obj = new Perm();
    obj.timePerm(1);
    return !obj.error;
  }

  public static void main(String[] args) {
    int rc = 0;
    Perm obj = new Perm();

    long before = System.currentTimeMillis();
    obj.timePerm(500);
    long after = System.currentTimeMillis();

    System.out.println("art_benchmarks/stanford/Perm: " + (after - before));

    if (!verify_Perm()) {
      rc++;
    }

    System.exit(rc);
  }
}