计算R中函数的复杂度

时间:2018-12-15 12:36:50

标签: r function time-complexity complexity-theory

我需要计算带有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)

还有其他替代方法吗,或者我可以根据需要更新这些功能

1 个答案:

答案 0 :(得分:2)

根据“复杂性”的构想,您有很多选择,仅举几例:

圈复杂度

内存使用

  • Base R提供了一个使用Rprofmem(纯内存使用分析器)来分析内存使用情况的选项(如果R是用定义的R_MEMORY_PROFILING编译的)。
  • 使用utils::Rprof(..., memory.profiling = TRUE)采样内存配置文件
  • profvis-Rprof的程序包扩展,具有非常好的图形输出,既节省了时间,又节省了内存-https://cran.r-project.org/web/packages/profvis/index.html

花费的时间