Skip to content

Commit 9971969

Browse files
committed
Merge branch 'master' of https://github.com/eugenp/tutorials
2 parents 0a01434 + 89e8d66 commit 9971969

File tree

186 files changed

+2388
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+2388
-697
lines changed

core-java-8/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@
1313
- [Strategy Design Pattern in Java 8](http://www.baeldung.com/java-strategy-pattern)
1414
- [Exceptions in Java 8 Lambda Expressions](http://www.baeldung.com/java-lambda-exceptions)
1515
- [Guide to Java 8 Comparator.comparing()](http://www.baeldung.com/java-8-comparator-comparing)
16-
- [Introduction to the Java 8 Date/Time API](http://www.baeldung.com/java-8-date-time-intro)
17-
- [Migrating to the New Java 8 Date Time API](http://www.baeldung.com/migrating-to-java-8-date-time-api)
1816
- [Guide To Java 8 Optional](http://www.baeldung.com/java-optional)
1917
- [Guide to the Java 8 forEach](http://www.baeldung.com/foreach-java)
20-
- [Get the Current Date, Time and Timestamp in Java 8](http://www.baeldung.com/current-date-time-and-timestamp-in-java-8)
21-
- [TemporalAdjuster in Java](http://www.baeldung.com/java-temporal-adjuster)
2218
- [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max)
2319
- [Java Base64 Encoding and Decoding](http://www.baeldung.com/java-base64-encode-and-decode)
2420
- [The Difference Between map() and flatMap()](http://www.baeldung.com/java-difference-map-and-flatmap)
25-
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
2621
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
2722
- [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods)
2823
- [Efficient Word Frequency Calculator in Java](http://www.baeldung.com/java-word-frequency)
@@ -34,15 +29,10 @@
3429
- [Finding Min/Max in an Array with Java](http://www.baeldung.com/java-array-min-max)
3530
- [Internationalization and Localization in Java 8](http://www.baeldung.com/java-8-localization)
3631
- [How to Find an Element in a List with Java](http://www.baeldung.com/find-list-element-java)
37-
- [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time)
3832
- [Java Optional – orElse() vs orElseGet()](http://www.baeldung.com/java-optional-or-else-vs-or-else-get)
3933
- [An Introduction to Java.util.Hashtable Class](http://www.baeldung.com/java-hash-table)
4034
- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection)
4135
- [Java 8 Unsigned Arithmetic Support](http://www.baeldung.com/java-unsigned-arithmetic)
42-
- [How to Get the Start and the End of a Day using Java](http://www.baeldung.com/java-day-start-end)
4336
- [Generalized Target-Type Inference in Java](http://www.baeldung.com/java-generalized-target-type-inference)
44-
- [Calculate Age in Java](http://www.baeldung.com/java-get-age)
4537
- [Copy a List to Another List in Java](http://www.baeldung.com/java-copy-list-to-another)
46-
- [Increment Date in Java](http://www.baeldung.com/java-increment-date)
47-
- [Add Hours To a Date In Java](http://www.baeldung.com/java-add-hours-date)
4838
- [Overriding System Time for Testing in Java](http://www.baeldung.com/java-override-system-time)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.primitive;
2+
3+
public class BenchmarkRunner {
4+
5+
public static void main(String[] args) throws Exception {
6+
new IntPrimitiveLookup().run();
7+
new IntegerWrapperLookup().run();
8+
new FloatPrimitiveLookup().run();
9+
new FloatWrapperLookup().run();
10+
new DoublePrimitiveLookup().run();
11+
new DoubleWrapperLookup().run();
12+
new ShortPrimitiveLookup().run();
13+
new ShortWrapperLookup().run();
14+
new BooleanPrimitiveLookup().run();
15+
new BooleanWrapperLookup().run();
16+
new CharPrimitiveLookup().run();
17+
new CharacterWrapperLookup().run();
18+
new BytePrimitiveLookup().run();
19+
new ByteWrapperLookup().run();
20+
new LongPrimitiveLookup().run();
21+
new LongWrapperLookup().run();
22+
}
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.baeldung.primitive;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Thread)
6+
public class BooleanPrimitiveLookup extends Lookup {
7+
8+
private boolean[] elements;
9+
private final boolean pivot = false;
10+
11+
@Setup
12+
@Override
13+
public void prepare() {
14+
elements = new boolean[s];
15+
for (int i = 0; i < s - 1; i++) {
16+
elements[i] = true;
17+
}
18+
elements[s - 1] = pivot;
19+
}
20+
21+
@TearDown
22+
@Override
23+
public void clean() {
24+
elements = null;
25+
}
26+
27+
28+
@Benchmark
29+
@BenchmarkMode(Mode.AverageTime)
30+
public int findPosition() {
31+
int index = 0;
32+
while (pivot != elements[index]) {
33+
index++;
34+
}
35+
return index;
36+
}
37+
38+
@Override
39+
public String getSimpleClassName() {
40+
return BooleanPrimitiveLookup.class.getSimpleName();
41+
}
42+
43+
44+
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.baeldung.primitive;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Thread)
6+
public class BooleanWrapperLookup extends Lookup {
7+
private Boolean[] elements;
8+
private final boolean pivot = false;
9+
10+
@Override
11+
@Setup
12+
public void prepare() {
13+
elements = new Boolean[s];
14+
for (int i = 0; i < s - 1; i++) {
15+
elements[i] = true;
16+
}
17+
elements[s - 1] = pivot;
18+
}
19+
20+
@Override
21+
@TearDown
22+
public void clean() {
23+
elements = null;
24+
}
25+
26+
@Override
27+
@Benchmark
28+
@BenchmarkMode(Mode.AverageTime)
29+
public int findPosition() {
30+
int index = 0;
31+
Boolean pivotWrapper = pivot;
32+
while (!pivotWrapper.equals(elements[index])) {
33+
index++;
34+
}
35+
return index;
36+
37+
}
38+
39+
@Override
40+
public String getSimpleClassName() {
41+
return BooleanWrapperLookup.class.getSimpleName();
42+
}
43+
44+
45+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.primitive;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Thread)
6+
public class BytePrimitiveLookup extends Lookup {
7+
8+
private byte[] elements;
9+
private final byte pivot = 2;
10+
11+
@Setup
12+
@Override
13+
public void prepare() {
14+
byte common = 1;
15+
elements = new byte[s];
16+
for (int i = 0; i < s - 1; i++) {
17+
elements[i] = common;
18+
}
19+
elements[s - 1] = pivot;
20+
}
21+
22+
@TearDown
23+
@Override
24+
public void clean() {
25+
elements = null;
26+
}
27+
28+
29+
@Benchmark
30+
@BenchmarkMode(Mode.AverageTime)
31+
public int findPosition() {
32+
int index = 0;
33+
while (pivot != elements[index]) {
34+
index++;
35+
}
36+
return index;
37+
}
38+
39+
@Override
40+
public String getSimpleClassName() {
41+
return BytePrimitiveLookup.class.getSimpleName();
42+
}
43+
44+
45+
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.primitive;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Thread)
6+
public class ByteWrapperLookup extends Lookup {
7+
private Byte[] elements;
8+
private final byte pivot = 2;
9+
10+
@Override
11+
@Setup
12+
public void prepare() {
13+
byte common = 1;
14+
elements = new Byte[s];
15+
for (int i = 0; i < s - 1; i++) {
16+
elements[i] = common;
17+
}
18+
elements[s - 1] = pivot;
19+
}
20+
21+
@Override
22+
@TearDown
23+
public void clean() {
24+
elements = null;
25+
}
26+
27+
@Override
28+
@Benchmark
29+
@BenchmarkMode(Mode.AverageTime)
30+
public int findPosition() {
31+
int index = 0;
32+
Byte pivotWrapper = pivot;
33+
while (!pivotWrapper.equals(elements[index])) {
34+
index++;
35+
}
36+
return index;
37+
38+
}
39+
40+
@Override
41+
public String getSimpleClassName() {
42+
return ByteWrapperLookup.class.getSimpleName();
43+
}
44+
45+
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.primitive;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Thread)
6+
public class CharPrimitiveLookup extends Lookup {
7+
8+
private char[] elements;
9+
private final char pivot = 'b';
10+
11+
@Setup
12+
@Override
13+
public void prepare() {
14+
char common = 'a';
15+
elements = new char[s];
16+
for (int i = 0; i < s - 1; i++) {
17+
elements[i] = common;
18+
}
19+
elements[s - 1] = pivot;
20+
}
21+
22+
@TearDown
23+
@Override
24+
public void clean() {
25+
elements = null;
26+
}
27+
28+
29+
@Benchmark
30+
@BenchmarkMode(Mode.AverageTime)
31+
public int findPosition() {
32+
int index = 0;
33+
while (pivot != elements[index]) {
34+
index++;
35+
}
36+
return index;
37+
}
38+
39+
@Override
40+
public String getSimpleClassName() {
41+
return CharPrimitiveLookup.class.getSimpleName();
42+
}
43+
44+
45+
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.primitive;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Thread)
6+
public class CharacterWrapperLookup extends Lookup {
7+
private Character[] elements;
8+
private final char pivot = 'b';
9+
10+
@Override
11+
@Setup
12+
public void prepare() {
13+
char common = 'a';
14+
elements = new Character[s];
15+
for (int i = 0; i < s - 1; i++) {
16+
elements[i] = common;
17+
}
18+
elements[s - 1] = pivot;
19+
}
20+
21+
@Override
22+
@TearDown
23+
public void clean() {
24+
elements = null;
25+
}
26+
27+
@Override
28+
@Benchmark
29+
@BenchmarkMode(Mode.AverageTime)
30+
public int findPosition() {
31+
int index = 0;
32+
Character pivotWrapper = pivot;
33+
while (!pivotWrapper.equals(elements[index])) {
34+
index++;
35+
}
36+
return index;
37+
38+
}
39+
40+
@Override
41+
public String getSimpleClassName() {
42+
return CharacterWrapperLookup.class.getSimpleName();
43+
}
44+
45+
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.baeldung.primitive;
2+
3+
import org.openjdk.jmh.annotations.*;
4+
5+
@State(Scope.Thread)
6+
public class DoublePrimitiveLookup extends Lookup {
7+
private double[] elements;
8+
private final double pivot = 2;
9+
10+
@Setup
11+
@Override
12+
public void prepare() {
13+
double common = 1;
14+
elements = new double[s];
15+
for (int i = 0; i < s - 1; i++) {
16+
elements[i] = common;
17+
}
18+
elements[s - 1] = pivot;
19+
}
20+
21+
@TearDown
22+
@Override
23+
public void clean() {
24+
elements = null;
25+
}
26+
27+
28+
@Benchmark
29+
@BenchmarkMode(Mode.AverageTime)
30+
public int findPosition() {
31+
int index = 0;
32+
while (pivot != elements[index]) {
33+
index++;
34+
}
35+
return index;
36+
}
37+
38+
@Override
39+
public String getSimpleClassName() {
40+
return DoublePrimitiveLookup.class.getSimpleName();
41+
}
42+
}

0 commit comments

Comments
 (0)