Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
どのKotlinが一番速い?
Yuta Tomiyama
September 26, 2020
Programming
1
76
どのKotlinが一番速い?
Zli × excite 合同LT にて発表
Yuta Tomiyama
September 26, 2020
Tweet
Share
More Decks by Yuta Tomiyama
See All by Yuta Tomiyama
今だからこそ知りたいKotlin Multiplatform
yt8492
0
36
State management and API calls in Jetpack Compose: Learning Apollo + Jetpack Compose through React Hooks
yt8492
0
760
サーバーフレームワークの仕組みが気になったので車輪の再発明をしてみた
yt8492
0
69
Compose for Webを始めよう
yt8492
0
190
Compose Multiplatform 1.0.0
yt8492
0
74
Kotlin/NativeからCの標準ライブラリを呼び出そう
yt8492
0
81
2021年のKotlin入門
yt8492
0
170
Jetpack Compose + Decomposeで始めるクロスプラットフォーム開発
yt8492
1
210
Kotlin/MPPでブログを作った話
yt8492
0
510
Other Decks in Programming
See All in Programming
Excelの助けを借りて楽にシナリオを作ろう
rpa_niiyama
0
320
Cloudflare WorkersでGoを動かすライブラリを作っている話
syumai
1
320
Spring BootとKubernetesで実現する今どきのDevOps入門
xblood
0
390
Circuit⚡
monaapk
0
200
NGK2023S - OCaml最高! スマホ開発にも使えちゃう?!
haochenxie
0
120
Hono v3 - Do Everything, Run Anywhere, But Small, And Faster
yusukebe
4
130
AWSとCPUのムフフな関係
cmdemura
0
480
An Advanced Introduction to R
nicetak
0
1.8k
LIFFで動く割り勘アプリTATEKAをリリースしてみた話
inoue2002
0
260
Azure Functionsをサクッと開発、サクッとデプロイ/vscodeconf2023-baba
nina01
1
350
なぜRubyコミュニティにコミットするのか?
luccafort
0
320
ITエンジニア特化型Q&Aサイトteratailを 言語、DB、クラウドなど フルリプレイスした話
leveragestech
0
420
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
15
1.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
6
4.5k
Atom: Resistance is Futile
akmur
256
24k
Code Review Best Practice
trishagee
50
11k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
224
50k
Bootstrapping a Software Product
garrettdimon
299
110k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
182
15k
Side Projects
sachag
451
37k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
318
19k
Happy Clients
brianwarren
90
5.8k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
120
29k
How to train your dragon (web standard)
notwaldorf
66
4.3k
Transcript
どのKotlinが一番速い? 2020/09/26 Zli × excite 合同LT
自己紹介 HN: マヤミト 本名: 富山雄太 会津大学26期 (学部3年) Zli 現代表 GitHub:
https://github.com/yt8492 趣味: なんでもKotlinで作ること yt8492.com Twitter: yt8492
前提知識: Kotlinについて - Androidアプリ開発などに主に使われているJVM言語 - Kotlin/JSはKotlinをJSにトランスパイルする - Kotlin/NativeはKotlinをネイティブバイナリにコンパイルできる 011011 001010
101110 110001
ある日のぼく 「Kotlinたのし〜〜〜〜〜!!!!!!」 「Kotlin/JSたのし〜〜〜〜〜!!!!!!」 「Kotlin/Nativeたのし〜〜〜〜〜!!!!!!」 「どのKotlinが一番速いんだ……?」
検証方法 1. Kotlin/MPPでプラットフォームに依存しないテスト用コードを書く 2. ビルドする a. 実行可能なjarファイルを生成する b. nodeで実行可能なjsファイルを生成する c.
MacOSネイティブで実行可能なバイナリファイルを生成する 3. timeコマンドで計測する
環境 - MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
- macOS Catalina 10.15.6 - CPU 2.3GHz クアッドコアIntel Core i7 - メモリ 32GB 3733MHz - OpenJDK 1.8.0_265 - node 12.18.3
テスト用コード ランダムに生成した配列をマージソートするだけのプログラム
各プラットフォームから参照する commonモジュールに置いたテスト用コードを各プラットフォー ムのモジュールから参照する プラットフォームごとにmain関数を用意し、そこからテスト用の 関数を呼び出す
JVM向けにビルド - Gradleのapplication pluginとshadow jar pluginの設定をjvm/build.gradle.ktsに 記述 - GradleのshadowJarタスクを実行し実行可能なjarファイルを生成 ./gradlew
:jvm:shadowJar - jvm/build/libs以下に生成される
Node.js向けにビルド - Kotlin/JSのbrowser向けの設定をjs/build.gradle.ktsに記述 - webpack-node-externalsの依存を追加し、node向けのビルドの設定を記述 - GradleのbrowserProductionWebpackタスクを実行しjsファイルを生成 ./gradlew :js:browserProductionWebpack -
js/build/distributions以下に生成される
MacOSネイティブ向けにビルド - Kotlin/NativeのMacOS向けの設定をnative/build.gradle.ktsに記述 - GradleのmacosMainBinariesタスクを実行しバイナリファイルを生成 ./gradlew :native:macosMainBinaries - native/build/bin/macos/releaseExecutable以下に生成される
それぞれの実行結果
timeコマンドを使って測定 - zshのtimeコマンドを使い、実行時間を測定する - それぞれ10回ずつ実行し、平均値を見る
予想 - JVMのほうがNode.jsより早そう - バイナリになるKotlin/Nativeは結構速いのでは?
Kotlin/JVM 測定結果 user: 1.229s system: 0.18s total: 1.181s
Kotlin/JS 測定結果 user: 1.683s system: 0.103s total: 1.716s
Kotlin/Native 測定結果 user: 2.060s system: 0.068s total: 2.140s
おまけ: GraalVM native-image jarファイルをnative-imageに 一番速かったが今回の趣旨からは若干離れる気がしたので割愛
実験結果 - Kotlin/JVM < Kotlin/JS < Kotlin/Native - Kotlin/Nativeはtotalで見るとKotlin/JVMの倍近く実行時間がかかったが、system 時間は一番速かった
- やはりJVMは速い
今回のリポジトリ yt8492/SpeedTest https://github.com/yt8492/SpeedTest