Skip to content

Commit 2c7e0ad

Browse files
committed
stopwatch
1 parent 2f36b12 commit 2c7e0ad

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<artifactId>commons-math3</artifactId>
2525
<version>3.6.1</version>
2626
</dependency>
27+
<dependency>
28+
<groupId>org.apache.commons</groupId>
29+
<artifactId>commons-lang3</artifactId>
30+
<version>3.12.0</version>
31+
</dependency>
2732
</dependencies>
2833

2934
</project>

src/main/java/save/santa/day11/Main.java

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package save.santa.day11;
22

3+
import org.apache.commons.lang3.time.StopWatch;
34
import org.javatuples.Pair;
45

56
import java.io.IOException;
@@ -13,8 +14,13 @@
1314

1415
public class Main {
1516
public static void main(String[] args) throws IOException {
17+
StopWatch watch = new StopWatch();
18+
watch.start();
1619
System.out.println("part01: " + part01(2));
1720
System.out.println("part02: " + part01(1_000_000));
21+
watch.stop();
22+
23+
System.out.println("Time: " + watch.formatTime());
1824
}
1925

2026
public static long part01(int expansionFactor) throws IOException {
@@ -40,6 +46,7 @@ public static long part01(int expansionFactor) throws IOException {
4046
return stars.stream()
4147
.flatMap(star1 -> stars.stream().map(star2 -> Pair.with(star1, star2)))
4248
.filter(starPair -> !starPair.getValue0().equals(starPair.getValue1()))
49+
.parallel()
4350
.map(starPair -> distanceBetweenStars(starPair.getValue0(), starPair.getValue1(), emptyXs, emptyYs, expansionFactor))
4451
.reduce(Long::sum)
4552
.orElseThrow() / 2;

0 commit comments

Comments
 (0)