< prev index next >

test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/jdk/incubator/vector/DoubleScalar.java

Print this page
rev 55606 : 8221812: Fine-tune jmh test for vector api
Summary: To compare performance of vector api and auto vectorization, vector
api and scalar test cases are updated to keep aligned.
Reviewed-by: duke

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -25,18 +25,21 @@
 
 import java.util.concurrent.TimeUnit;
 import java.util.function.IntFunction;
 
 import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.infra.Blackhole;
 
 @BenchmarkMode(Mode.Throughput)
 @OutputTimeUnit(TimeUnit.MILLISECONDS)
 @State(Scope.Benchmark)
 @Warmup(iterations = 3, time = 1)
 @Measurement(iterations = 5, time = 1)
 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
 public class DoubleScalar extends AbstractVectorBenchmark {
+    static final int INVOC_COUNT = 1; // To align with vector benchmarks.
+
     @Param("1024")
     int size;
 
     double[] fill(IntFunction<Double> f) {
         double[] array = new double[size];

@@ -70,147 +73,163 @@
     final IntFunction<boolean[]> fmr = vl -> rms;
     final IntFunction<int[]> fs = vl -> ss;
 
 
     @Benchmark
-    public Object add() {
+    public void add(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(a + b);
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object addMasked() {
+    public void addMasked(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             if (ms[i % ms.length]) {
                 rs[i] = (double)(a + b);
             } else {
                 rs[i] = a;
             }
         }
-        return rs;
+        }
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object sub() {
+    public void sub(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(a - b);
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object subMasked() {
+    public void subMasked(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             if (ms[i % ms.length]) {
                 rs[i] = (double)(a - b);
             } else {
                 rs[i] = a;
             }
         }
-        return rs;
+        }
+        bh.consume(rs);
     }
 
 
     @Benchmark
-    public Object div() {
+    public void div(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(a / b);
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object divMasked() {
+    public void divMasked(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             if (ms[i % ms.length]) {
                 rs[i] = (double)(a / b);
             } else {
                 rs[i] = a;
             }
         }
-        return rs;
+        }
+        bh.consume(rs);
     }
 
 
     @Benchmark
-    public Object mul() {
+    public void mul(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(a * b);
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object mulMasked() {
+    public void mulMasked(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             if (ms[i % ms.length]) {
                 rs[i] = (double)(a * b);
             } else {
                 rs[i] = a;
             }
         }
-        return rs;
+        }
+        bh.consume(rs);
     }
 
 
 
 

@@ -240,739 +259,837 @@
 
 
 
 
     @Benchmark
-    public Object max() {
+    public void max(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(Math.max(a, b));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object min() {
+    public void min(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(Math.min(a, b));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
 
     @Benchmark
-    public double addAll() {
+    public void addAll(Blackhole bh) {
         double[] as = fa.apply(size);
         double r = 0;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = 0;
         for (int i = 0; i < as.length; i++) {
             r += as[i];
         }
-        return r;
+        }
+        bh.consume(r);
     }
 
     @Benchmark
-    public double mulAll() {
+    public void mulAll(Blackhole bh) {
         double[] as = fa.apply(size);
         double r = 1;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = 1;
         for (int i = 0; i < as.length; i++) {
             r *= as[i];
         }
-        return r;
+        }
+        bh.consume(r);
     }
 
     @Benchmark
-    public double minAll() {
+    public void minAll(Blackhole bh) {
         double[] as = fa.apply(size);
         double r = Double.POSITIVE_INFINITY;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = Double.POSITIVE_INFINITY;
         for (int i = 0; i < as.length; i++) {
             r = (double)Math.min(r, as[i]);
         }
-        return r;
+        }
+        bh.consume(r);
     }
 
     @Benchmark
-    public double maxAll() {
+    public void maxAll(Blackhole bh) {
         double[] as = fa.apply(size);
         double r = Double.NEGATIVE_INFINITY;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = Double.NEGATIVE_INFINITY;
         for (int i = 0; i < as.length; i++) {
             r = (double)Math.max(r, as[i]);
         }
-        return r;
+        }
+        bh.consume(r);
     }
 
 
 
     @Benchmark
-    public boolean lessThan() {
+    public void lessThan(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
 
         boolean r = false;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = false;
         for (int i = 0; i < as.length; i++) {
             boolean m = (as[i] < bs[i]);
             r |= m; // accumulate so JIT can't eliminate the computation
         }
+        }
 
-        return r;
+        bh.consume(r);
     }
 
     @Benchmark
-    public boolean greaterThan() {
+    public void greaterThan(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
 
         boolean r = false;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = false;
         for (int i = 0; i < as.length; i++) {
             boolean m = (as[i] > bs[i]);
             r |= m; // accumulate so JIT can't eliminate the computation
         }
+        }
 
-        return r;
+        bh.consume(r);
     }
 
     @Benchmark
-    public boolean equal() {
+    public void equal(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
 
         boolean r = false;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = false;
         for (int i = 0; i < as.length; i++) {
             boolean m = (as[i] == bs[i]);
             r |= m; // accumulate so JIT can't eliminate the computation
         }
+        }
 
-        return r;
+        bh.consume(r);
     }
 
     @Benchmark
-    public boolean notEqual() {
+    public void notEqual(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
 
         boolean r = false;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = false;
         for (int i = 0; i < as.length; i++) {
             boolean m = (as[i] != bs[i]);
             r |= m; // accumulate so JIT can't eliminate the computation
         }
+        }
 
-        return r;
+        bh.consume(r);
     }
 
     @Benchmark
-    public boolean lessThanEq() {
+    public void lessThanEq(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
 
         boolean r = false;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = false;
         for (int i = 0; i < as.length; i++) {
             boolean m = (as[i] <= bs[i]);
             r |= m; // accumulate so JIT can't eliminate the computation
         }
+        }
 
-        return r;
+        bh.consume(r);
     }
 
     @Benchmark
-    public boolean greaterThanEq() {
+    public void greaterThanEq(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
 
         boolean r = false;
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
+            r = false;
         for (int i = 0; i < as.length; i++) {
             boolean m = (as[i] >= bs[i]);
             r |= m; // accumulate so JIT can't eliminate the computation
         }
+        }
 
-        return r;
+        bh.consume(r);
     }
 
     @Benchmark
-    public Object blend() {
+    public void blend(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             boolean m = ms[i % ms.length];
             rs[i] = (m ? b : a);
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
-    Object rearrangeShared(int window) {
+    void rearrangeShared(int window, Blackhole bh) {
         double[] as = fa.apply(size);
         int[] order = fs.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i += window) {
             for (int j = 0; j < window; j++) {
                 double a = as[i+j];
                 int pos = order[j];
                 rs[i + pos] = a;
             }
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object rearrange064() {
+    public void rearrange064(Blackhole bh) {
         int window = 64 / Double.SIZE;
-        return rearrangeShared(window);
+        rearrangeShared(window, bh);
     }
 
     @Benchmark
-    public Object rearrange128() {
+    public void rearrange128(Blackhole bh) {
         int window = 128 / Double.SIZE;
-        return rearrangeShared(window);
+        rearrangeShared(window, bh);
     }
 
     @Benchmark
-    public Object rearrange256() {
+    public void rearrange256(Blackhole bh) {
         int window = 256 / Double.SIZE;
-        return rearrangeShared(window);
+        rearrangeShared(window, bh);
     }
 
     @Benchmark
-    public Object rearrange512() {
+    public void rearrange512(Blackhole bh) {
         int window = 512 / Double.SIZE;
-        return rearrangeShared(window);
+        rearrangeShared(window, bh);
     }
 
 
     @Benchmark
-    public Object sin() {
+    public void sin(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.sin((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object exp() {
+    public void exp(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.exp((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object log1p() {
+    public void log1p(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.log1p((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object log() {
+    public void log(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.log((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object log10() {
+    public void log10(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.log10((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object expm1() {
+    public void expm1(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.expm1((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object cos() {
+    public void cos(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.cos((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object tan() {
+    public void tan(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.tan((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object sinh() {
+    public void sinh(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.sinh((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object cosh() {
+    public void cosh(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.cosh((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object tanh() {
+    public void tanh(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.tanh((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object asin() {
+    public void asin(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.asin((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object acos() {
+    public void acos(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.acos((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object atan() {
+    public void atan(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.atan((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object cbrt() {
+    public void cbrt(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.cbrt((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object hypot() {
+    public void hypot(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(Math.hypot((double)a, (double)b));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object pow() {
+    public void pow(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(Math.pow((double)a, (double)b));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object atan2() {
+    public void atan2(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             rs[i] = (double)(Math.atan2((double)a, (double)b));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object fma() {
+    public void fma(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] cs = fc.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             double c = cs[i];
             rs[i] = (double)(Math.fma(a, b, c));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
 
     @Benchmark
-    public Object fmaMasked() {
+    public void fmaMasked(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] bs = fb.apply(size);
         double[] cs = fc.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             double b = bs[i];
             double c = cs[i];
             if (ms[i % ms.length]) {
                 rs[i] = (double)(Math.fma(a, b, c));
             } else {
                 rs[i] = a;
             }
         }
-        return rs;
+        }
+        bh.consume(rs);
     }
 
 
     @Benchmark
-    public Object neg() {
+    public void neg(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(-((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object negMasked() {
+    public void negMasked(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             boolean m = ms[i % ms.length];
             rs[i] = (m ? (double)(-((double)a)) : a);
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object abs() {
+    public void abs(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.abs((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object absMasked() {
+    public void absMasked(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             boolean m = ms[i % ms.length];
             rs[i] = (m ? (double)(Math.abs((double)a)) : a);
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
 
     @Benchmark
-    public Object sqrt() {
+    public void sqrt(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             rs[i] = (double)(Math.sqrt((double)a));
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
 
     @Benchmark
-    public Object sqrtMasked() {
+    public void sqrtMasked(Blackhole bh) {
         double[] as = fa.apply(size);
         double[] rs = fr.apply(size);
         boolean[] ms = fm.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             double a = as[i];
             boolean m = ms[i % ms.length];
             rs[i] = (m ? (double)(Math.sqrt((double)a)) : a);
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
     @Benchmark
-    public Object gatherBase0() {
+    public void gatherBase0(Blackhole bh) {
         double[] as = fa.apply(size);
         int[] is    = fs.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             int ix = 0 + is[i];
             rs[i] = as[ix];
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
 
-    Object gather(int window) {
+    void gather(int window, Blackhole bh) {
         double[] as = fa.apply(size);
         int[] is    = fs.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i += window) {
             for (int j = 0; j < window; j++) {
                 int ix = i + is[i + j];
                 rs[i + j] = as[ix];
             }
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object gather064() {
+    public void gather064(Blackhole bh) {
         int window = 64 / Double.SIZE;
-        return gather(window);
+        gather(window, bh);
     }
 
     @Benchmark
-    public Object gather128() {
+    public void gather128(Blackhole bh) {
         int window = 128 / Double.SIZE;
-        return gather(window);
+        gather(window, bh);
     }
 
     @Benchmark
-    public Object gather256() {
+    public void gather256(Blackhole bh) {
         int window = 256 / Double.SIZE;
-        return gather(window);
+        gather(window, bh);
     }
 
     @Benchmark
-    public Object gather512() {
+    public void gather512(Blackhole bh) {
         int window = 512 / Double.SIZE;
-        return gather(window);
+        gather(window, bh);
     }
 
 
 
     @Benchmark
-    public Object scatterBase0() {
+    public void scatterBase0(Blackhole bh) {
         double[] as = fa.apply(size);
         int[] is    = fs.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i++) {
             int ix = 0 + is[i];
             rs[ix] = as[i];
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
-    Object scatter(int window) {
+    void scatter(int window, Blackhole bh) {
         double[] as = fa.apply(size);
         int[] is    = fs.apply(size);
         double[] rs = fr.apply(size);
 
+        for (int ic = 0; ic < INVOC_COUNT; ic++) {
         for (int i = 0; i < as.length; i += window) {
             for (int j = 0; j < window; j++) {
                 int ix = i + is[i + j];
                 rs[ix] = as[i + j];
             }
         }
+        }
 
-        return rs;
+        bh.consume(rs);
     }
 
     @Benchmark
-    public Object scatter064() {
+    public void scatter064(Blackhole bh) {
         int window = 64 / Double.SIZE;
-        return scatter(window);
+        scatter(window, bh);
     }
 
     @Benchmark
-    public Object scatter128() {
+    public void scatter128(Blackhole bh) {
         int window = 128 / Double.SIZE;
-        return scatter(window);
+        scatter(window, bh);
     }
 
     @Benchmark
-    public Object scatter256() {
+    public void scatter256(Blackhole bh) {
         int window = 256 / Double.SIZE;
-        return scatter(window);
+        scatter(window, bh);
     }
 
     @Benchmark
-    public Object scatter512() {
+    public void scatter512(Blackhole bh) {
         int window = 512 / Double.SIZE;
-        return scatter(window);
+        scatter(window, bh);
     }
 
 }
 
< prev index next >