summaryrefslogtreecommitdiff
path: root/BenchmarkFramework/app/src/main/java/art_benchmarks/micro/PrefetchLoopedArrayAccess.java
blob: df7862deeb84abef875ab805a508e34f43c2f23a (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
/*
 * Copyright (C) 2015 Linaro Limited. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/*
 * Description:     Tracks performance of looped array access to Java Objects.
 *                  BitSet is an arbitrary choice. 1024 pool and update list
 *                  sizes showed benefits when prefetching 8 references ahead
 *                  during looped array access. Other benchmarks for different
 *                  and mixed Object sizes would be beneficial.
 * Main Focus:      Looped array access to semi-random memory access patterns.
 * Secondary Focus:
 *
 */

package art_benchmarks.micro;

import java.util.BitSet;
import java.util.Random;

public class PrefetchLoopedArrayAccess {

  private static final Random rnd = new Random(0);
  private static final int POOL_Size = 1024;
  private static final int UPDATE_Size = 1024;

  private BitSet[] bits;
  private BitSet[] updateList;

  {
    initBitSets();
    initUpdateList();
  }

  private void initUpdateList() {
    updateList = new BitSet[UPDATE_Size];
    for (int i = 0; i < UPDATE_Size; i++) {
      updateList[i] = bits[rnd.nextInt(POOL_Size)];
    }
  }

  private void initBitSets() {
    bits = new BitSet[POOL_Size];
    for (int i = 0; i < POOL_Size; i++) {
      bits[i] = new BitSet();
    }
  }

  private void updateBitSets() {
    for (int i = 0; i < UPDATE_Size; i++) {
      updateList[i].set(7);
    }
  }

  public void timeRun(int iterations) {
    for (int i = 0; i < iterations; i++) {
      updateBitSets();
    }
  }

  public static void main(String[] args) {
    PrefetchLoopedArrayAccess obj = new PrefetchLoopedArrayAccess();
    long before = System.currentTimeMillis();
    obj.timeRun(22000);
    long after = System.currentTimeMillis();
    System.out.println("art_benchmarks/micro/PrefetchLoopedArrayAccess: " + (after - before));
  }

}