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


##########
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:
   I tried that and didn't observe a significant difference, so I prefer to 
leave it as is.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to