Skip to content

Commit 658145c

Browse files
committed
Refactor benchmarks for BigInts & BigDecimals to work with up to 128-bit numbers
1 parent c266e6e commit 658145c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/ArrayOfBigDecimalsBenchmark.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import play.api.libs.json.Json
1414
class ArrayOfBigDecimalsBenchmark extends CommonParams {
1515
val sourceObj: Array[BigDecimal] = (1 to 128).map { i =>
1616
//FIXME | 1 is used to hide JDK bug of serialization redundant 0 after .
17-
BigDecimal(BigInt(Array.fill((i & 31) + 1)((i | 1).toByte)), i % 32)
18-
}.toArray // up to 256-bit numbers
17+
BigDecimal(BigInt(Array.fill((i & 15) + 1)((i | 1).toByte)), i % 37)
18+
}.toArray // up to 128-bit numbers for unscaledVal and up to 37-digit (~127 bits) scale
1919
val jsonString: String = sourceObj.mkString("[", ",", "]")
2020
val jsonBytes: Array[Byte] = jsonString.getBytes
2121

benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/ArrayOfBigIntsBenchmark.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import io.circe.parser._
1212
import org.openjdk.jmh.annotations.Benchmark
1313

1414
class ArrayOfBigIntsBenchmark extends CommonParams {
15-
val obj: Array[BigInt] = (1 to 128).map(i => BigInt(Array.fill((i & 31) + 1)(i.toByte))).toArray // up to 256-bit numbers
15+
val obj: Array[BigInt] = (1 to 128).map(i => BigInt(Array.fill((i & 15) + 1)(i.toByte))).toArray // up to 128-bit numbers
1616
val jsonString: String = obj.map(x => new java.math.BigDecimal(x.bigInteger).toPlainString).mkString("[", ",", "]")
1717
val jsonBytes: Array[Byte] = jsonString.getBytes
1818

0 commit comments

Comments
 (0)