summaryrefslogtreecommitdiff
path: root/src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java')
-rw-r--r--src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java b/src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java
new file mode 100644
index 0000000..d70a20a
--- /dev/null
+++ b/src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java
@@ -0,0 +1,78 @@
+/*
+ * 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 org.linaro.benchmarks.micro;
+
+import java.util.BitSet;
+import java.util.Random;
+import org.openjdk.jmh.annotations.*;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@State(Scope.Benchmark)
+
+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);
+ }
+ }
+
+ @Benchmark
+ public void jmhTimeRun() {
+ updateBitSets();
+ }
+}