microbenchmark: Accurate Timing Functions

ベンチマークテスト

> library(microbenchmark)

バージョン: 1.4.2.1


関数名 概略
autoplot.microbenchmark Autoplot method for microbenchmark objects: Prettier graphs for microbenchmark using ggplot2
boxplot.microbenchmark Boxplot of 'microbenchmark' timings.
coalesce Return first non null argument.
convert_to_unit Convert timings to different units.
find_prefix Find SI prefix for unit
get_nanotime Return the current value of the platform timer.
microbenchmark Sub-millisecond accurate timing of expression evaluation.
microtiming_precision Estimate precision of timing routines.
print.microbenchmark Print 'microbenchmark' timings.
summary.microbenchmark Summarize 'microbenchmark' timings.

autoplot

ベンチマークテストの結果を図示

ref) boxplot()

> x <- runif(100)
> microbenchmark(
+   sqrt(x),
+   x ^ 0.5,
+   times = 200,
+   unit = "us"
+ ) %>% autoplot()

boxplot

ベンチマークテストの結果を図示

> x <- runif(100)
> microbenchmark(
+   sqrt(x),
+   x ^ 0.5,
+   times = 200,
+   unit = "us"
+ ) %>% boxplot()

convert_to_unit

ns, us, ms, s, t, hz, eps, khz, mhz, f

> microbenchmark(
+   mean(c(1, 3, 10, 8)),
+   unit = "us") %>% {
+     microbenchmark:::convert_to_unit(., unit = "ns")
+   }

microbenchmark

ベンチマークテストを実施する

Arguments

  • ... ベンチマークを測る処理。複数あるを比較する場合はカンマを使って区切る
  • list
  • times... 繰り返しの数。初期値で100回
  • unit
  • check
  • control
> x <- runif(100)
> microbenchmark(
+   sqrt(x),
+   x ^ 0.5,
+   times = 200,
+   unit = "us"
+ )
Unit: microseconds
    expr  min    lq     mean median     uq    max neval cld
 sqrt(x) 0.69 0.772 1.631205 0.8245 1.7460 62.829   200  a 
   x^0.5 3.14 3.271 3.829265 3.3595 4.2625 10.908   200   b