File tree Expand file tree Collapse file tree 17 files changed +217
-214
lines changed
Expand file tree Collapse file tree 17 files changed +217
-214
lines changed Original file line number Diff line number Diff line change 1- // arrays/Prefix1 .java
1+ // arrays/ParallelPrefix1 .java
22// (c)2016 MindView LLC: see Copyright.txt
33// We make no guarantees that this code is fit for any purpose.
44// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55import java .util .*;
66import onjava .*;
77import static onjava .ArrayShow .*;
88
9- public class Prefix1 {
9+ public class ParallelPrefix1 {
1010 public static void main (String [] args ) {
1111 int [] nums = new Count .int_ ().array (10 );
1212 show (nums );
Original file line number Diff line number Diff line change 1- // arrays/Prefix2 .java
1+ // arrays/ParallelPrefix2 .java
22// (c)2016 MindView LLC: see Copyright.txt
33// We make no guarantees that this code is fit for any purpose.
44// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55import java .util .*;
66import onjava .*;
77import static onjava .ArrayShow .*;
88
9- public class Prefix2 {
9+ public class ParallelPrefix2 {
1010 public static void main (String [] args ) {
1111 String [] strings = new Rand .String (1 ).array (8 );
1212 show (strings );
Original file line number Diff line number Diff line change 1- // arrays/ParallelPrefix .java
1+ // arrays/ParallelPrefix3 .java
22// (c)2016 MindView LLC: see Copyright.txt
33// We make no guarantees that this code is fit for any purpose.
44// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55import java .util .*;
66
7- public class ParallelPrefix {
7+ public class ParallelPrefix3 {
88 static final int SIZE = 10_000_000 ;
99 public static void main (String [] args ) {
1010 long [] nums = new long [SIZE ];
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1414print (aSlice ) # [3, 4]
1515
1616class MyList (list ): # Inherit from list
17- # Define a method, 'this' pointer is explicit:
17+ # Define a method; 'this' pointer is explicit:
1818 def getReversed (self ):
1919 reversed = self [:] # Copy list using slices
2020 reversed .reverse () # Built-in list method
Original file line number Diff line number Diff line change 1+ // arrays/jmh/ParallelSort.java
2+ // (c)2016 MindView LLC: see Copyright.txt
3+ // We make no guarantees that this code is fit for any purpose.
4+ // Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5+ package arrays .jmh ;
6+ import java .util .*;
7+ import onjava .*;
8+ import org .openjdk .jmh .annotations .*;
9+
10+ @ State (Scope .Thread )
11+ public class ParallelSort {
12+ private long [] la ;
13+ @ Setup
14+ public void setup () {
15+ la = new Rand .long_ ().array (100_000 );
16+ }
17+ @ Benchmark
18+ public void sort () {
19+ Arrays .sort (la );
20+ }
21+ @ Benchmark
22+ public void parallelSort () {
23+ Arrays .parallelSort (la );
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ subprojects {
229229
230230 // Exclude java sources that will not compile
231231 if (tags. compileTimeError) {
232+ println " >>> Excluding " + file. name
232233 sourceSets. main. java. excludes. add(file. name)
233234 } else {
234235 JavaExec javaTask = null
Original file line number Diff line number Diff line change 33// We make no guarantees that this code is fit for any purpose.
44// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55import java .util .*;
6- import static onjava .TimeIt .*;
76
87public class BadMicroBenchmark {
98 static final int SIZE = 20_000_000 ;
109 public static void main (String [] args ) {
1110 long [] la = new long [SIZE ];
1211 System .out .print ("setAll: " );
13- timeIt (() -> Arrays .setAll (la , n -> n ));
12+ Time . it (() -> Arrays .setAll (la , n -> n ));
1413 System .out .print ("parallelSetAll: " );
15- timeIt (() -> Arrays .parallelSetAll (la , n -> n ));
14+ Time . it (() -> Arrays .parallelSetAll (la , n -> n ));
1615 }
1716}
1817/* Output:
Original file line number Diff line number Diff line change 44// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55// Reversing the test order
66import java .util .*;
7- import static onjava .TimeIt .*;
87
98public class BadMicroBenchmark2 {
109 static final int SIZE = 20_000_000 ;
1110 public static void main (String [] args ) {
1211 long [] la = new long [SIZE ];
1312 System .out .print ("parallelSetAll: " );
14- timeIt (() -> Arrays .parallelSetAll (la , n -> n ));
13+ Time . it (() -> Arrays .parallelSetAll (la , n -> n ));
1514 System .out .print ("setAll: " );
16- timeIt (() -> Arrays .setAll (la , n -> n ));
15+ Time . it (() -> Arrays .setAll (la , n -> n ));
1716 }
1817}
1918/* Output:
Original file line number Diff line number Diff line change 44// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55// Relying on a common resource
66import java .util .*;
7- import static onjava .TimeIt .*;
87
98public class BadMicroBenchmark3 {
109 static final int SIZE = 20_000_000 ;
1110 public static void main (String [] args ) {
1211 long [] la = new long [SIZE ];
1312 Random r = new Random ();
1413 System .out .print ("parallelSetAll: " );
15- timeIt (() ->
14+ Time . it (() ->
1615 Arrays .parallelSetAll (la , n -> r .nextLong ()));
1716 System .out .print ("setAll: " );
18- timeIt (() ->
17+ Time . it (() ->
1918 Arrays .setAll (la , n -> r .nextLong ()));
2019 SplittableRandom sr = new SplittableRandom ();
2120 System .out .print ("parallelSetAll: " );
22- timeIt (() ->
21+ Time . it (() ->
2322 Arrays .parallelSetAll (la , n -> sr .nextLong ()));
2423 System .out .print ("setAll: " );
25- timeIt (() ->
24+ Time . it (() ->
2625 Arrays .setAll (la , n -> sr .nextLong ()));
2726 }
2827}
You can’t perform that action at this time.
0 commit comments