使用Sys.time()创建的强制转换对象

时间:2016-07-29 20:34:14

标签: r performance time performance-testing

我正在测量嵌套foreach循环中几个函数的性能,以便做到这一点

start <- Sys.time()
<corpus of function>
end <- Sys.time()
diff_time = end - start

问题在于,对象假设类“ diff_time ”并且我无法使用ggplot2绘制它。

有可能一些比其他模拟更快的模拟将具有后缀 sec 而其他 mins ?如果发生这种情况,我该如何避免这些问题?

1 个答案:

答案 0 :(得分:2)

您可以在将 difftime 转换为数字时指定单位。

t = difftime(time1 = "2016-01-02 01:00:00", time2 = "2016-01-02 00:30:00")
t
# Time difference of 30 mins

as.numeric(t, units = "secs")
# [1] 1800