R microbenchmark和autoplot?

时间:2015-04-04 17:11:15

标签: r microbenchmark

我有几个关于microbenchmark和autoplot的问题

假设这是我的代码:

library("ggplot2")
tm <- microbenchmark(rchisq(100, 0),rchisq(100, 1),rchisq(100, 2),rchisq(100, 3),rchisq(100, 5), times=1000L)
autoplot(tm)
  1. tm $时间内的单位是多少?我怎么能把它转换成秒?
  2. 如何将x轴上的标记更改为seq(从= 0到= 100,按= 5)?
  3. 谢谢!

1 个答案:

答案 0 :(得分:4)

help(microbenchmark)给出:

1.  ‘time’ is the measured execution time
    of the expression in nanoseconds.

NANOseconds 不是毫秒或微秒。

因此除以1000000000转换为秒。

对于你的第二个问题,我的第一个回答是&#34;为什么?&#34;。但它基于ggplot,所以你可以通过添加ggplot来覆盖位:

 autoplot(tm) + scale_y_log10(name="seq(whatever)")

请注意,绘图是旋转的,因此x轴是y刻度....

我只是觉得你真的是指&#34;刻度线&#34;?略有不同但可行,但考虑到对数轴不太合适。您可以使用指定的刻度标记强制非对数轴:

 autoplot(tm) + scale_y_continuous(breaks=seq(0,10000,len=5),name="not a log scale")

您可以保留对数刻度并设置刻度线点:

 autoplot(tm) + scale_y_log10(breaks=c(50,200,500))