Skip to content

Commit f2db979

Browse files
committed
Replace an old example by benchmarking Math.multiplyHigh
1 parent 9d7c554 commit f2db979

File tree

4 files changed

+52
-217
lines changed

4 files changed

+52
-217
lines changed

jsoniter-scala-examples/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ user 0m34.748s
198198
sys 0m2.362s
199199
```
200200

201-
### Build GraalVM native image, print its size, and measure its running time (tested with Oracle GraalVM 24/23)
201+
### Build GraalVM native image, print its size, and measure its running time (tested with Oracle GraalVM 24)
202202

203203
```sh
204204
scala-cli --power package --graalvm-jvm-id graalvm-oracle:24 --native-image example02.sc --force -o example02_graalvm.bin -- --no-fallback --gc=epsilon -O3 -H:+UnlockExperimentalVMOptions -R:MaxHeapSize=16m -H:-GenLoopSafepoints -H:-ParseRuntimeOptions -H:-IncludeMethodData --initialize-at-build-time
@@ -225,3 +225,34 @@ real 0m49.766s
225225
user 0m47.408s
226226
sys 0m2.355s
227227
```
228+
229+
## Benchmarking `Math.multiplyHigh` (example03)
230+
231+
### Build uber jar and measure its running time (tested with Open JDK 21)
232+
233+
```sh
234+
scala-cli --power package --assembly example03.scala --force -o example03.jar
235+
time ./example03.jar -J-XX:+UnlockExperimentalVMOptions -J-XX:+UseEpsilonGC -J-Xms32m -J-Xmx32m -J-XX:+AlwaysPreTouch
236+
```
237+
Expected output:
238+
```text
239+
9223372036854775806
240+
241+
real 0m11.017s
242+
user 0m11.059s
243+
sys 0m0.038s
244+
```
245+
246+
### Build Scala Native image and measure its running time
247+
```sh
248+
scala-cli --power package --native-version 0.5.8 --native example03.scala --native-mode release-full --native-gc none --native-lto thin --native-multithreading=false --force -o example03_native.bin
249+
time ./example03_native.bin
250+
```
251+
Expected output:
252+
```text
253+
9223372036854775806
254+
255+
real 0m16.668s
256+
user 0m16.660s
257+
sys 0m0.006s
258+
```

jsoniter-scala-examples/example03.sc

Lines changed: 0 additions & 213 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using dep "com.github.plokhotnyuk.jsoniter-scala::jsoniter-scala-core::2.36.3"
2+
3+
package com.github.plokhotnyuk.jsoniter_scala.core
4+
5+
object Main extends App {
6+
var r = 0x3333333333333333L
7+
var i = 1L
8+
while (i <= 10000000000L) {
9+
r += Math.multiplyHigh(r, i) // Replace by `NativeMath.multiplyHigh` for Scala Native
10+
i += 1L
11+
}
12+
println(r)
13+
}

release.sbt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import scala.sys.process._
2-
import sbtrelease.ReleaseStateTransformations._
1+
import scala.sys.process.*
2+
import sbtrelease.ReleaseStateTransformations.*
33

44
lazy val ensureJDK11: ReleaseStep = { st: State =>
55
val javaVersion = System.getProperty("java.specification.version")
@@ -23,7 +23,11 @@ lazy val updateVersionInReadmeAndExamples: ReleaseStep = { st: State =>
2323
}
2424

2525
updateFile("README.md")
26-
(1 to 3).foreach(n => updateFile(s"jsoniter-scala-examples/example0$n.sc"))
26+
Seq(
27+
"example01.sc",
28+
"example02.sc",
29+
"example03.scala",
30+
).foreach(x => updateFile(s"jsoniter-scala-examples/$x"))
2731

2832
st
2933
}

0 commit comments

Comments
 (0)