Last active
August 29, 2015 14:06
-
-
Save cgrand/313faf2b6410eba74ff5 to your computer and use it in GitHub Desktop.
jmh.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 0c89fecf532c7c73468164290af03bbed5559f3f Mon Sep 17 00:00:00 2001 | |
From: Christophe Grand <christophe@cgrand.net> | |
Date: Tue, 16 Sep 2014 13:36:36 +0200 | |
Subject: [PATCH] fix clojure benchmark | |
--- | |
.../arithmetic/EuclidianGcdMicroBenchmark.java | 8 ++++++++ | |
.../main/resources/snippets/clojure/arithmetic.clj | 23 +++++++++++++++++----- | |
2 files changed, 26 insertions(+), 5 deletions(-) | |
diff --git a/jmh-benchmarks/src/main/java/org/gololang/microbenchmarks/arithmetic/EuclidianGcdMicroBenchmark.java b/jmh-benchmarks/src/main/java/org/gololang/microbenchmarks/arithmetic/EuclidianGcdMicroBenchmark.java | |
index 94c7ac3..2504763 100644 | |
--- a/jmh-benchmarks/src/main/java/org/gololang/microbenchmarks/arithmetic/EuclidianGcdMicroBenchmark.java | |
+++ b/jmh-benchmarks/src/main/java/org/gololang/microbenchmarks/arithmetic/EuclidianGcdMicroBenchmark.java | |
@@ -125,11 +125,13 @@ public class EuclidianGcdMicroBenchmark { | |
static public class ClojureState { | |
Var gcd; | |
Var gcd_fast; | |
+ Var gcd_safe_fast; | |
@Setup(Level.Trial) | |
public void prepare() { | |
gcd = new CodeLoader().clojure("arithmetic", "arithmetic", "gcd"); | |
gcd_fast = new CodeLoader().clojure("arithmetic", "arithmetic", "fast-gcd"); | |
+ gcd_safe_fast = new CodeLoader().clojure("arithmetic", "arithmetic", "safe-fast-gcd"); | |
} | |
} | |
@@ -235,6 +237,12 @@ public class EuclidianGcdMicroBenchmark { | |
} | |
@Benchmark | |
+ public Object clojure_safe_fast(DataSpace dataSpace, ClojureState clojureState) { | |
+ int index = dataSpace.nextIndex(); | |
+ return clojureState.gcd_safe_fast.invoke(dataSpace.x[index], dataSpace.y[index], dataSpace.repeat); | |
+ } | |
+ | |
+ @Benchmark | |
public Object clojure_fast(DataSpace dataSpace, ClojureState clojureState) { | |
int index = dataSpace.nextIndex(); | |
return clojureState.gcd_fast.invoke(dataSpace.x[index], dataSpace.y[index], dataSpace.repeat); | |
diff --git a/jmh-benchmarks/src/main/resources/snippets/clojure/arithmetic.clj b/jmh-benchmarks/src/main/resources/snippets/clojure/arithmetic.clj | |
index 6ee6dc1..4592c40 100644 | |
--- a/jmh-benchmarks/src/main/resources/snippets/clojure/arithmetic.clj | |
+++ b/jmh-benchmarks/src/main/resources/snippets/clojure/arithmetic.clj | |
@@ -1,14 +1,21 @@ | |
(ns arithmetic) | |
(defn -gcd [a b] | |
- (if (= a b) | |
+ (if (== a b) | |
a | |
(if (> a b) | |
(recur (- a b) b) | |
(recur a (- b a)) ))) | |
-(defn ^long -fast-gcd [^long a ^long b] | |
- (if (= a b) | |
+(defn -fast-gcd ^long [^long a ^long b] | |
+ (if (== a b) | |
+ a | |
+ (if (> a b) | |
+ (recur (unchecked-subtract a b) b) | |
+ (recur a (unchecked-subtract b a)) ))) | |
+ | |
+(defn -safe-fast-gcd ^long [^long a ^long b] | |
+ (if (== a b) | |
a | |
(if (> a b) | |
(recur (- a b) b) | |
@@ -20,9 +27,15 @@ | |
res | |
(recur a b (dec repeat-count)) ))) | |
-(defn ^long fast-gcd [^long a ^long b ^long repeat-count] | |
+(defn safe-fast-gcd ^long [^long a ^long b ^long repeat-count] | |
+ (let [res (-safe-fast-gcd a b)] | |
+ (if (zero? repeat-count) | |
+ res | |
+ (recur a b (unchecked-dec repeat-count)) ))) | |
+ | |
+(defn fast-gcd ^long [^long a ^long b ^long repeat-count] | |
(let [res (-fast-gcd a b)] | |
(if (zero? repeat-count) | |
res | |
- (recur a b (dec repeat-count)) ))) | |
+ (recur a b (unchecked-dec repeat-count)) ))) | |
-- | |
1.8.3.1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My Java: | |
``` | |
$ java -version | |
java version "1.8.0_05" | |
Java(TM) SE Runtime Environment (build 1.8.0_05-b13) | |
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) | |
``` | |
With master: | |
``` | |
java -jar target/microbenchmarks-golo-1.1.0-SNAPSHOT.jar -e 'org.gololang.microbenchmarks.(?!arithmetic.E.*(clojure|_java)).*' -f 3 -w 5s -r 5s -rf scsv -rff results.csv | |
Benchmark Mode Samples Score Score error Units | |
o.g.m.a.EuclidianGcdMicroBenchmark.baseline_java_mh ss 5 122,178 8,866 ms | |
o.g.m.a.EuclidianGcdMicroBenchmark.clojure ss 5 1474,302 282,492 ms | |
o.g.m.a.EuclidianGcdMicroBenchmark.clojure_fast ss 5 119,308 154,282 ms | |
``` | |
With my patch (==, proper hinting and unchecked ops): | |
``` | |
java -jar target/microbenchmarks-golo-1.1.0-SNAPSHOT.jar -e 'org.gololang.microbenchmarks.(?!arithmetic.E.*(clojure|_java)).*' -f 3 -w 5s -r 5s -rf scsv -rff results.csv | |
Benchmark Mode Samples Score Score error Units | |
o.g.m.a.EuclidianGcdMicroBenchmark.baseline_java_mh ss 15 122,933 4,181 ms | |
o.g.m.a.EuclidianGcdMicroBenchmark.clojure ss 15 1130,243 142,782 ms | |
o.g.m.a.EuclidianGcdMicroBenchmark.clojure_fast ss 15 49,850 5,252 ms | |
``` | |
Another run with regular (checked) ops in clojure_safe_fast: | |
``` | |
Benchmark Mode Samples Score Score error Units | |
o.g.m.a.EuclidianGcdMicroBenchmark.baseline_java_mh ss 15 128,253 5,889 ms | |
o.g.m.a.EuclidianGcdMicroBenchmark.clojure ss 15 1534,282 147,491 ms | |
o.g.m.a.EuclidianGcdMicroBenchmark.clojure_fast ss 15 64,241 7,589 ms | |
o.g.m.a.EuclidianGcdMicroBenchmark.clojure_safe_fast ss 15 124,803 14,780 ms | |
o.g.m.a.EuclidianGcdMicroBenchmark.golo ss 15 473,119 101,912 ms | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment