File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
src/main/java/org/codefx/demo/effective_java/_06_unnecessary_objects Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1+ package org .codefx .demo .effective_java ._06_unnecessary_objects ;
2+
3+ import org .openjdk .jmh .annotations .Benchmark ;
4+
5+ import java .util .HashMap ;
6+ import java .util .List ;
7+ import java .util .Map ;
8+
9+ public class Exceptions extends ObjectCreationBenchmarks {
10+
11+ @ Benchmark
12+ public Exception createException () {
13+ // NOTE expensive operation:
14+ // Exceptions capture the entire call stack, which takes some time.
15+ return new IllegalArgumentException ();
16+ }
17+
18+ @ Benchmark
19+ public Map <String , Integer > createMap () {
20+ var map = new HashMap <String , Integer >();
21+ map .put ("1" , 1 );
22+ map .put ("2" , 1 );
23+ map .put ("3" , 1 );
24+ return map ;
25+ }
26+
27+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public class UrlEquals extends ObjectCreationBenchmarks {
1414
1515 @ Benchmark
1616 public boolean urlEqual () throws MalformedURLException {
17- // NOTE unnecessary object :
17+ // NOTE expensive operation :
1818 // There isn't anything unnecessary here. It's just that URL::equals
1919 // resolves the host name, which can take a while...
2020 return new URL (blog ).equals (new URL (youtube ));
You can’t perform that action at this time.
0 commit comments