Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rコードのベンチマーク
Search
bob3bob3
October 20, 2022
Technology
1.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rコードのベンチマーク
Rコードのベンチマーク手法
bob3bob3
October 20, 2022
More Decks by bob3bob3
See All by bob3bob3
RとLLMで自然言語処理
bob3bob3
3
1.1k
RでPSM分析
bob3bob3
1
490
Rでコンジョイント分析 2024年版
bob3bob3
0
2.7k
『改訂新版前処理大全』の話と Apache Parquet の話 #TokyoR
bob3bob3
0
1.5k
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
670
『データ可視化学入門』をPythonからRに翻訳した話(増強版)
bob3bob3
0
620
『データ可視化学入門』を PythonからRに翻訳した話
bob3bob3
1
680
qeMLパッケージの紹介
bob3bob3
0
3k
「国と音楽」 ~spotifyrを用いて~ #muana
bob3bob3
2
680
Other Decks in Technology
See All in Technology
日経電子版を支えていく Kasane Design System/fec_fukuoka
nikkei_engineer_recruiting
0
1.5k
映像変換サーバーなしで端末内でHLSを生成してライブ配信
hikarusato
0
110
aws-iot-platform-architecture-use-cases.pdf
ma2shita
0
110
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
1.9k
アプリをもっと"iOSアプリっぽく"する小さな工夫 / Small Touches That Make Your App Feel More Like an iOS App
matsuji
1
890
beyond jj: config & tools ecosystem
indirect
0
410
開発投資の期待値を上げるプロダクトロードマップづくり ~プロダクトエンジニアが越境して事業を伸ばす~
kekekenta
1
160
品質と信頼性を地続きにする
grimoh
0
370
SREは、MCPとAutopilotをこう使え!
kazumax55
2
800
Minecraft JavaのMODをSwiftで作る
1mash0
0
160
あるけみー式LTスライド作成術
alchemy1115
1
210
AI時代の「技術的負債」の変質ー概念の終焉と再解釈、エージェントと共に向かう先
nwiizo
0
2.6k
Featured
See All Featured
We Are The Robots
honzajavorek
0
370
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
300
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
460
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.9k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
280
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
The Language of Interfaces
destraynor
162
27k
Discover your Explorer Soul
emna__ayadi
2
1.3k
Everyday Curiosity
cassininazir
0
320
Transcript
Rコードのベンチマーク Tokyo.R #102 2022/10/22 LT @bob3bob3
Rコードの実行時間を計る • Rの中級者になり、コードのいろいろな書き方が身についてくると「どんな書 き方をすると処理の効率がいいんだろう?」という疑問が湧いてくることが あります。 • 今回はRの実行時間を計る以下の三つの方法をお話しします。 ◦ base::system.time() ◦
tictocパッケージ ◦ microbenchmarkパッケージ
準備 • nycflights13のデータを使い、「月、 飛行機会社、出発地、目的地毎に 件数、飛行時間の平均値、中央 値、標準偏差を算出する」処理を dplyr、dtplyr、data.tableで書き、そ れぞれの実行速度を計る。 • デモデータは約33万行。
# ライブラリ library(tidyverse) library(dtplyr) library(data.table) library(nycflights13) # デモデータ dat <- flights |> left_join(planes, by = "tailnum")
準備:各処理の関数化 # dplyrでの処理を関数化 f_dplyr <- function(){ dat |> group_by(month, carrier,
origin, dest) |> summarise( 件数 = n(), 平均 = mean(air_time, na.rm = TRUE), 中央値 = median(air_time, na.rm = TRUE), .groups = "drop" ) } # dtplyrでの処理を関数化 f_dtplyr <- function(){ dat |> lazy_dt() |> group_by(month, carrier, origin, dest) |> summarise( 件数 = n(), 平均 = mean(air_time, na.rm = TRUE), 中央値 = median(air_time, na.rm = TRUE), .groups = "drop" ) |> as_tibble() }
準備:各処理の関数化 # data.tableでの処理を関数化 f_data.table <- function(){ dt <- dat |>
data.table( key=c("month", "carrier", "origin", "dest") ) dt[ , .( 件数 = .N, 平均 = air_time |> mean(na.rm = TRUE), 中央値 = air_time |> median(na.rm = TRUE) ), by = list(month, carrier, origin, dest) ] |> as_tibble() }
base::system.time() system.time()の第一引数に測定したい 処理を入れるだけ。
tictocパッケージ # tic()とtoc()で測定したい処理を挟む library(tictoc) tic() f_dplyr() toc() tic() f_dtplyr() toc()
tic() f_data.table() toc()
microbenchmarkパッケージ (1/3) • 複数の処理を一度に測定できる。 • 同じ処理を複数回試行して測定できる。 • 結果を可視化できる。
library(microbenchmark) res_micro <- microbenchmark( "dplyr"= f_dplyr(), "dtplyr" = f_dtplyr(), "data.table" = f_data.table(), times = 30 )
microbenchmarkパッケージ (2/3)
microbenchmarkパッケージ (3/3) # 測定結果の可視化 res_micro |> autoplot() # 素のdata.tableよりdtplyrの方が速いのは #
どこか書き方が悪いのだろうか?
Enjoy!