diff options
author | Ningsheng Jian <ningsheng.jian@linaro.org> | 2017-11-07 18:38:01 +0800 |
---|---|---|
committer | Ningsheng Jian <ningsheng.jian@linaro.org> | 2017-11-16 09:46:55 +0800 |
commit | e715fe64e96acb6131af937d0c8bba2537ea13f4 (patch) | |
tree | 702384eb404c3fd6acbbc3321261847e9fc27398 /src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java | |
parent | 3811e9930ddb1d2b3a1463ad6c876af324331335 (diff) |
1. Port benchmark cases from art-testing.
2. Add some more benchmarks for basic OPs.
3. Fix some jmh result variance.
Signed-off-by: Zhongwei Yao <zhongwei.yao@linaro.org>
Signed-off-by: Yang Zhang <yang.zhang@linaro.org>
Signed-off-by: Ningsheng Jian <ningsheng.jian@linaro.org>
Change-Id: I514658696b63e468158325be3b84494553773705
Diffstat (limited to 'src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java')
-rw-r--r-- | src/main/java/org/linaro/benchmarks/micro/PrefetchLoopedArrayAccess.java | 78 |
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(); + } +} |