-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from xp-vit/add-big-int-performance-test
BigDecimal perf tests
- Loading branch information
Showing
8 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
32 changes: 32 additions & 0 deletions
32
src/jmh/java/com/patotski/performance/bigdec/BigDecConstructor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.patotski.performance.bigdec; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.patotski.performance.utils.BenchmarkUtils.runBenchmark; | ||
|
||
@BenchmarkMode({Mode.AverageTime}) | ||
@Warmup(iterations = 2, time = 3, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Fork(1) | ||
public class BigDecConstructor { | ||
public static final BigDecimal BIG_DECIMAL = BigDecimal.valueOf(12.3456); | ||
|
||
@Benchmark | ||
public BigDecimal string() { | ||
return new BigDecimal("12.3456"); | ||
|
||
} | ||
|
||
@Benchmark | ||
public BigDecimal doubleCreation() { | ||
return new BigDecimal(12.3456); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
runBenchmark(BigDecConstructor.class); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/jmh/java/com/patotski/performance/bigdec/BigDecDivideVsMove.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.patotski.performance.bigdec; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.patotski.performance.utils.BenchmarkUtils.runBenchmark; | ||
|
||
@BenchmarkMode({Mode.AverageTime}) | ||
@Warmup(iterations = 2, time = 2, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Fork(1) | ||
public class BigDecDivideVsMove { | ||
public static final BigDecimal bigDecimal = BigDecimal.valueOf(12.3456); | ||
|
||
@Benchmark | ||
public BigDecimal divide() { | ||
return bigDecimal.divide(BigDecimal.valueOf(100)); | ||
} | ||
|
||
@Benchmark | ||
public BigDecimal move2Left() { | ||
return bigDecimal.movePointLeft(2); | ||
} | ||
|
||
@Benchmark | ||
public BigDecimal scaleByPowerOfTen() { | ||
return bigDecimal.scaleByPowerOfTen(-2); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
runBenchmark(BigDecDivideVsMove.class); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/jmh/java/com/patotski/performance/bigdec/BigDecMultiplyVsMove.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.patotski.performance.bigdec; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.regex.Pattern; | ||
|
||
import static com.patotski.performance.utils.BenchmarkUtils.runBenchmark; | ||
|
||
@BenchmarkMode({Mode.AverageTime}) | ||
@Warmup(iterations = 2, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Fork(1) | ||
public class BigDecMultiplyVsMove { | ||
public static final BigDecimal BIG_DECIMAL = BigDecimal.valueOf(12.3456); | ||
|
||
@Benchmark | ||
public BigDecimal multiply() { | ||
return BIG_DECIMAL.multiply(BigDecimal.valueOf(100)); | ||
} | ||
|
||
@Benchmark | ||
public BigDecimal move2Right() { | ||
return BIG_DECIMAL.movePointRight(2); | ||
} | ||
|
||
@Benchmark | ||
public BigDecimal scaleByPowerOfTen() { | ||
return BIG_DECIMAL.scaleByPowerOfTen(2); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
runBenchmark(BigDecMultiplyVsMove.class); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/jmh/java/com/patotski/performance/lombok/BigDecimalTuple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.patotski.performance.lombok; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public record BigDecimalTuple(BigDecimal first, BigDecimal second) { | ||
public static BigDecimalTupleBuilder builder() { | ||
return new BigDecimalTupleBuilder(); | ||
} | ||
|
||
public static class BigDecimalTupleBuilder { | ||
private BigDecimal first; | ||
private BigDecimal second; | ||
|
||
BigDecimalTupleBuilder() { | ||
} | ||
|
||
public BigDecimalTupleBuilder first(BigDecimal first) { | ||
this.first = first; | ||
return this; | ||
} | ||
|
||
public BigDecimalTupleBuilder second(BigDecimal second) { | ||
this.second = second; | ||
return this; | ||
} | ||
|
||
public BigDecimalTuple build() { | ||
return new BigDecimalTuple(this.first, this.second); | ||
} | ||
|
||
public String toString() { | ||
return "BigDecimalTuple.BigDecimalTupleBuilder(first=" + this.first + ", second=" + this.second + ")"; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/jmh/java/com/patotski/performance/lombok/BuilderVsConstructor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.patotski.performance.lombok; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.patotski.performance.utils.BenchmarkUtils.runBenchmark; | ||
|
||
|
||
@BenchmarkMode({Mode.AverageTime}) | ||
@Warmup(iterations = 2, time = 2, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = 10, time = 10, timeUnit = TimeUnit.SECONDS) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Fork(1) | ||
public class BuilderVsConstructor { | ||
public static final BigDecimal ONE_HUNDRED = new BigDecimal(100); | ||
|
||
@Benchmark | ||
public BigDecimalTuple builder() { | ||
return BigDecimalTuple.builder() | ||
.first(BigDecimal.ZERO) | ||
.second(BigDecimal.ONE) | ||
.build(); | ||
} | ||
|
||
@Benchmark | ||
public BigDecimalTuple constructor() { | ||
return new BigDecimalTuple(BigDecimal.ZERO, BigDecimal.ONE); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
runBenchmark(BuilderVsConstructor.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters