r - 根据内存使用量量化性能
问题描述
如何量化不同功能(或方法)的性能?我正在考虑类似system.time()
或microbenchmark::microbenchmark()
但用于内存使用的东西。在这个例子中,假设我想比较foo1()
vs foo2()
。我尝试修补,gc()
但无法让它用于比较。
set.seed(42)
x = sample(1:100000)
y = sample(1:100000)
foo1 = function(){
S = x + y
return(tail(which(S == max(S)), 1))
}
foo2 = function(){
S = x[1] + y[1]
i = 1
for (ind in 2:length(x)){
if ((x[ind] + y[ind]) > S){
S = x[ind] + y[ind]
i = ind
}
}
return(i)
}
identical(foo1(), foo2())
解决方案
推荐阅读
- python - Python Multiplication different shape to numpy dot product
- node.js - TypeError 无法将属性“firstName”设置为 null
- javascript - 使用烧瓶中的按钮取消选中并选中所有复选框
- python - 如何更改numpy数组中的每个偶数序列
- javascript - 使用javascript获取datalist选项值的选定值
- angular - 错误:文件 lib.dom.d.ts 没有 sourceFile
- ios - 在自定义单元格中实现倒数计时器
- vb.net - 尽管处于保护模式,但仍以编程方式启动 PDF
- php - 为什么我的 php 代码输出与使用 chr 的 C++ 不同
- php - 如何挂钩 get_files 函数