mlangc commented on code in PR #140:
URL: https://github.com/apache/commons-numbers/pull/140#discussion_r1509910402


##########
commons-numbers-examples/examples-jmh/src/main/java/org/apache/commons/numbers/examples/jmh/core/GcdPerformance.java:
##########
@@ -0,0 +1,236 @@
+package org.apache.commons.numbers.examples.jmh.core;
+
+import org.apache.commons.numbers.core.ArithmeticUtils;
+import org.apache.commons.rng.RestorableUniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+
+import java.math.BigInteger;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.Throughput)
+@Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
+@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
+@State(Scope.Benchmark)
+@Fork(value = 1, jvmArgs = {"-server", "-Xms512M", "-Xmx512M"})
+public class GcdPerformance {
+    private static final int NUM_PAIRS = 1000;
+    private static final long SEED = 42;
+
+    @State(Scope.Benchmark)
+    public static class Ints {
+        final int[] values;
+
+
+        public Ints() {
+            values = getRandomProvider().ints().filter(i -> i != 
Integer.MIN_VALUE).limit(NUM_PAIRS * 2).toArray();
+        }
+    }
+
+    @State(Scope.Benchmark)
+    public static class Longs {
+        final long[] values;
+
+
+        public Longs() {
+            values = getRandomProvider().longs().filter(i -> i != 
Long.MIN_VALUE).limit(NUM_PAIRS * 2).toArray();
+        }
+    }
+
+    private static RestorableUniformRandomProvider getRandomProvider() {
+        return RandomSource.XO_RO_SHI_RO_128_PP.create(SEED);
+    }
+
+    @Benchmark
+    public void gcdInt(Ints ints, Blackhole blackhole) {
+        for (int i = 0; i < ints.values.length; i += 2) {
+            blackhole.consume(ArithmeticUtils.gcd(ints.values[i], 
ints.values[i + 1]));

Review Comment:
   Thanks for the remark - I will check if there are any differences.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to