我需要计算带有R的长函数(600 lignes)的复杂度。 我想要的结果可能看起来像这样
start calculate complexity
**My function**
End calculate complexity
result= " the complexity of this function is x
我认为我想念我,但是我在基准测试中发现的只是运行时间
start.time <- Sys.time()
*****function*****
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken
此功能仅适用于向量
complexity(x, scaleMin, scaleMax, width = 7, measure = "complexity",
rescale = FALSE)
还有其他替代方法吗,或者我可以根据需要更新这些功能
答案 0 :(得分:2)
根据“复杂性”的构想,您有很多选择,仅举几例:
圈复杂度
内存使用
Rprofmem
(纯内存使用分析器)来分析内存使用情况的选项(如果R是用定义的R_MEMORY_PROFILING编译的)。utils::Rprof(..., memory.profiling = TRUE)
采样内存配置文件花费的时间
system.time
返回两个proc.time
调用之间的差,在该两次调用中,它计算作为参数提供的表达式。最简单的用法:system.time(runif(10^8))