Skip to content

Commit a619e3b

Browse files
author
Glen K. Peterson
committed
Improved benchmarks so they reuse the same 16 Integers instead of boxing primitive ints. Ratios are all still similar (this project vs. Clojure, Scala, and ArrayList) but everything is a little faster across the board.
1 parent 82cd8e4 commit a619e3b

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

paguro-bench/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ java -jar target/benchmarks.jar -f 2 -i 10 -wi 10
5151
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5252
<modelVersion>4.0.0</modelVersion>
5353

54-
<groupId>org.organicdesign.fp</groupId>
54+
<groupId>org.organicdesign</groupId>
5555
<artifactId>paguro-bench</artifactId>
5656
<version>1.0</version>
5757
<packaging>jar</packaging>
@@ -71,7 +71,7 @@ java -jar target/benchmarks.jar -f 2 -i 10 -wi 10
7171
<dependency>
7272
<groupId>org.organicdesign</groupId>
7373
<artifactId>Paguro</artifactId>
74-
<version>3.0.1-ALPHA</version>
74+
<version>3.0.3-ALPHA</version>
7575
</dependency>
7676
<dependency>
7777
<groupId>org.openjdk.jmh</groupId>

paguro-bench/src/main/java/org/organicdesign/fp/MyBenchmark.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -24,66 +24,74 @@
2424
@SuppressWarnings("WeakerAccess")
2525
public class MyBenchmark {
2626

27+
private static final Integer[] INTS =
28+
new Integer[] { Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(2),
29+
Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5),
30+
Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8),
31+
Integer.valueOf(9), Integer.valueOf(10), Integer.valueOf(11),
32+
Integer.valueOf(12), Integer.valueOf(13), Integer.valueOf(14),
33+
Integer.valueOf(15) };
34+
2735
static List<Integer> buildList2(int maxIdx) {
2836
List<Integer> empty = new ArrayList<>();
2937
for (int i = 0; i < maxIdx; i++) {
30-
empty.add(i);
38+
empty.add(INTS[i & 0xf]);
3139
}
3240
return empty;
3341
}
3442

3543
static scala.collection.immutable.Vector<Integer> buildScala(int maxIdx) {
3644
scala.collection.immutable.Vector<Integer> empty = Vector$.MODULE$.empty();
3745
for (int i = 0; i < maxIdx; i++) {
38-
empty = empty.appendBack(i);
46+
empty = empty.appendBack(INTS[i & 0xf]);
3947
}
4048
return empty;
4149
}
4250

4351
@SuppressWarnings("unchecked")
4452
static <T extends BaseList<Integer>> T buildList(T empty, int maxIdx) {
4553
for (int i = 0; i < maxIdx; i++) {
46-
empty = (T) empty.append(i);
54+
empty = (T) empty.append(INTS[i & 0xf]);
4755
}
4856
return empty;
4957
}
5058

5159
static ImRrbt<Integer> insertAtZeroRrb(int maxIdx) {
5260
ImRrbt<Integer> empty = empty();
5361
for (int i = maxIdx; i >= 0; i--) {
54-
empty = empty.insert(0, i);
62+
empty = empty.insert(0, INTS[i & 0xf]);
5563
}
5664
return empty;
5765
}
5866

5967
public static MutableRrbt<Integer> insertAtZeroRrbMut(int maxIdx) {
6068
MutableRrbt<Integer> empty = RrbTree.emptyMutable();
6169
for (int i = maxIdx; i >= 0; i--) {
62-
empty = empty.insert(0, i);
70+
empty = empty.insert(0, INTS[i & 0xf]);
6371
}
6472
return empty;
6573
}
6674

6775
public static List<Integer> insertAtZeroList(int maxIdx) {
6876
ArrayList<Integer> empty = new ArrayList<>();
6977
for (int i = maxIdx; i >= 0; i--) {
70-
empty.add(0, i);
78+
empty.add(0, INTS[i & 0xf]);
7179
}
7280
return empty;
7381
}
7482

7583
public static scala.collection.immutable.Vector<Integer> insertAtZeroScala(int maxIdx) {
7684
scala.collection.immutable.Vector<Integer> empty = Vector$.MODULE$.empty();
7785
for (int i = maxIdx; i >= 0; i--) {
78-
empty = empty.appendFront(i);
86+
empty = empty.appendFront(INTS[i & 0xf]);
7987
}
8088
return empty;
8189
}
8290

8391
public static RrbTree<Integer> randomInsertRrb(RrbTree empty, int maxIdx) {
8492
Random rnd = new Random();
8593
for (int i = 0; i < maxIdx; i++) {
86-
empty = empty.insert(i > 1 ? rnd.nextInt(i) : 0, i);
94+
empty = empty.insert(i > 1 ? rnd.nextInt(i) : 0, INTS[i & 0xf]);
8795
}
8896
return empty;
8997
}
@@ -92,7 +100,7 @@ public static List<Integer> randomInsertList(int maxIdx) {
92100
Random rnd = new Random();
93101
List<Integer> empty = new ArrayList<>();
94102
for (int i = 0; i < maxIdx; i++) {
95-
empty.add(i > 1 ? rnd.nextInt(i) : 0, i);
103+
empty.add(i > 1 ? rnd.nextInt(i) : 0, INTS[i & 0xf]);
96104
}
97105
return empty;
98106
}
@@ -272,7 +280,7 @@ static Integer getEachScala(scala.collection.immutable.Vector<Integer> is) {
272280
@Benchmark public void BuildList100000() { buildList2(100000); }
273281
@Benchmark public void BuildList1000000() { buildList2(1000000); }
274282
@Benchmark public void BuildList10000000() { buildList2(10000000); }
275-
@Benchmark public void BuildList100000000() { buildList2(100000000); }
283+
// TOO Long: @Benchmark public void BuildList100000000() { buildList2(100000000); }
276284

277285
@Benchmark public void BuildRrb1() { buildList(empty(), 1); }
278286
@Benchmark public void BuildRrb10() { buildList(empty(), 10); }

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ http://mvnrepository.com/artifact/org.organicdesign/Paguro
3838
-->
3939
<groupId>org.organicdesign</groupId>
4040
<artifactId>Paguro</artifactId>
41-
<version>3.0.1-ALPHA</version>
41+
<version>3.0.3-ALPHA</version>
4242
<packaging>jar</packaging>
4343

4444
<name>Paguro</name>

src/test/java/org/organicdesign/fp/collections/RrbTreeTest.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,25 @@ private static RrbTree<Integer> buildInOrderTest(RrbTree<Integer> is, int iterat
5858
buildInOrderTest(RrbTree.emptyMutable(), 100000);
5959
}
6060

61+
// private static final Integer[] INTS =
62+
// new Integer[] { Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(2),
63+
// Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5),
64+
// Integer.valueOf(6), Integer.valueOf(7), Integer.valueOf(8),
65+
// Integer.valueOf(9), Integer.valueOf(10), Integer.valueOf(11),
66+
// Integer.valueOf(12), Integer.valueOf(13), Integer.valueOf(14),
67+
// Integer.valueOf(15) };
68+
6169
// @Test public void testAppendSpeed() {
6270
// MutableRrbt<Integer> is = RrbTree.emptyMutable();
6371
// for (int j = 0; j < 1000000000; j++) {
64-
// is.append(j);
72+
// is.append(INTS[j & 0xf]);
6573
// }
74+
// }
6675
//// System.out.println("timer1: " + MutableRrbt.timer1);
6776
//// System.out.println("timer2: " + MutableRrbt.timer2);
6877
//// System.out.println("timer3: " + MutableRrbt.timer3);
6978
//// System.out.println("timer4: " + MutableRrbt.timer4);
7079
//// System.out.println("timer5: " + MutableRrbt.timer5);
71-
// }
7280

7381
private static RrbTree<Integer> buildReverseOrderTest(RrbTree<Integer> is, int iterations) {
7482
ArrayList<Integer> control = new ArrayList<>();

0 commit comments

Comments
 (0)