Running functions in R multiple times during benchmarking

前端 未结 3 698
故里飘歌
故里飘歌 2021-02-01 23:56

I am trying to measure the computation time of a function in R using system.time(). I want to run the function a few hundred times to get an average but I don\'t w

3条回答
  •  走了就别回头了
    2021-02-02 00:13

    The microbenchmark package takes a ,times= option and has the added bonus of being a bit more accurate.

    > library(microbenchmark)
    > m <- microbenchmark( seq(10)^2, (1:10)^2, times=10000)
    > m
    Unit: nanoseconds
           expr   min    lq median    uq     max
    1  (1:10)^2  2567  3423   3423  4278   41918
    2 seq(10)^2 44484 46195  46195 47051 1804147
    > plot(m)
    

    plot microbenchmark

    And using the not-yet-released autoplot() method for ggplot2:

    autoplot(m)
    

    autoplot microbenchmark

提交回复
热议问题