*[UPDATED, SEE RESULTS...] Two Questions*: I time...
# getting-started
d
[UPDATED, SEE RESULTS...] Two Questions: I timed the main( ) only, i.e. just the main execution {block} in all cases: 1. Is it typical that kotlinc .jar is ~10% faster than the kotlinc-native .exe native? 2. is there any way to optimize the kotlinc-native build akin to a --release mode flag/switch or does it default to fastest possible build? Background: Calculate the first 30 anti-primes and time various target's runtimes. Built/ran in W11 Pro 64-bit script (all from Rosetta Code) Kotlin: v1.9.22-release-704 (JRE 21.0.1+12-LTS) C++: C++23 g++ via MinGW-W64 x86_64-ucrt-mcf-seh via winlibs latest v13.2.0 build Results: • antiprimes.jar (kotlinc w/runtime): 9,205 ms (ran with java -jar ...) • antiprimes.jar (kotlinc no runtime): 9,098 ms (ran with kotlinc -classpath...) • antiprimes.exe (kotlinc-native): 10,942 ms [UPDATED: now 6,800 ms with -opt flag, thanks Shawn !!!] • antiprimes.exe (C++23 native): 6,118 ms (just as benchmark, same algorithm, used -O3 max speed optimization flag) BTW, Kotlin (all cases) did very good, extremely respectable speed! I am impressed and happy. Thank you for reading and any suggestions. (edited)
1
s
not sure about the numbers themselves (microbenchmark data isn't often considered especially informative nor especially easy to interpret accurately), but I was curious about what optimization looks like with
kotlinc-native
, so I dug around in the docs a bit and all I really found was that apparently you can turn "compiler optimizations" on with a flag https://kotlinlang.org/docs/compiler-reference.html#opt I had a hard time finding anything more concrete than that, though apparently there may be a way for you to manually specify Clang optimization flags, as described here https://github.com/JetBrains/kotlin/blob/master/kotlin-native/HACKING.md#llvm
🙌 2
🙏 1
d
Shawn you are awesome!!!! I used the -opt flag and now the kotlinc-native is running repeatably at 6,800 ms !! Just shy of C++23 with -O3 max optimization. I thought it could since it is using LLVM. Thank you for taking the time to read my post and doing your research and sharing!
s
lol happy to to help, good luck with your compilation research