我正在测量嵌套foreach循环中几个函数的性能,以便做到这一点
start <- Sys.time()
<corpus of function>
end <- Sys.time()
diff_time = end - start
问题在于,对象假设类“ diff_time ”并且我无法使用ggplot2绘制它。
有可能一些比其他模拟更快的模拟将具有后缀 sec 而其他 mins ?如果发生这种情况,我该如何避免这些问题?
答案 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