Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 037a08e

Browse files
committed
Fix some GitHub display errors
1 parent 3cd3783 commit 037a08e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Readme.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ http://oracl.info/xu1B50ypCAU
2020
2121
image::doc/ERb3bnYX0AACSXK.png[]
2222
____
23+
24+
2325
While this does of course work, it may not be the best solution (both in terms of readability and in terms of performance).
2426

2527
Other suggestions made in the replies were:
@@ -51,7 +53,16 @@ I decided to add one further alternative, which uses streams and may be more com
5153
5254
[source, java]
5355
----
56+
ifdef::env-github[]
57+
List<String> collect = IntStream.range(0, names.length)
58+
.mapToObj(index -> index + ": " + names[index])
59+
.collect(Collectors.toList());
60+
61+
collect.forEach(blackhole::consume);
62+
endif::[]
63+
ifndef::env-github[]
5464
include::src/main/java/com/github/blalasaadri/MyBenchmark.java[tag=streams_in_one_go, indent=0]
65+
endif::[]
5566
----
5667
The original stream solution looped through the names twice (once when mapping them and once when printing them).
5768
This solution only goes through them once (since `forEach` is the only https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps[terminal stream operation], whereas in the original solution there was also `collect`.)
@@ -169,7 +180,19 @@ AUTO_GENERATED_NAMES::
169180
+
170181
[source, java]
171182
----
183+
ifdef::env-github[]
184+
// 1000 new names
185+
final String[] firstNames = {"Alice", "Bob", "Charles", "Dora", "Emanuel", "Fabienne", "George", "Hannelore", "Igor", "Janice"};
186+
final String[] middleNames = {"Kim", "Landry", "Maria", "Nikita", "Oakley", "Perry", "Quin", "Robin", "Skyler", "Taylen"};
187+
final String[] surnames = {"Underhill", "Vaccanti", "Wilson", "Xanders", "Yallopp", "Zabawa", "Anderson", "Bell", "Carter", "Diaz"};
188+
names = Arrays.stream(firstNames)
189+
.flatMap(firstName -> Arrays.stream(middleNames).map(middleName -> firstName + " " + middleName))
190+
.flatMap(firstAndMiddleName -> Arrays.stream(surnames).map(surname -> firstAndMiddleName + " " + surname))
191+
.toArray(String[]::new);
192+
endif::[]
193+
ifndef::env-github[]
172194
include::src/main/java/com/github/blalasaadri/MyBenchmark.java[tag=autogenerate_names, indent=0]
195+
endif::[]
173196
----
174197
This name generation occurs within a function annotated with https://javadoc.io/doc/org.openjdk.jmh/jmh-core/latest/org/openjdk/jmh/annotations/Setup.html:[`@Setup(Leve.Trial)`].
175198
This means, that the array is generated before each trial and this generation will _not_ be included in the measurement itself.
@@ -303,6 +326,7 @@ ____
303326
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
304327
____
305328

329+
306330
This microbenchmark suite can not (and does not try to) measure readability, in part because this is subjective.
307331
However, here are my thoughts on the three implementations.
308332

0 commit comments

Comments
 (0)