我正在尝试进行一组计算的基准测试,如下所示 -
def benchmark(func, index, array)
start = Time.now
func(index, array)
start - Time.now #returns time taken to perform func
end
def func1(index, array)
#perform computations based on index and array
end
def func2(index, array)
#more computations....
end
benchmark(func1, index1, array1)
benchmark(func1, index2, array2)
现在我想知道如何实现这个。我尝试了这个例子,但是它输出了。
`func1': wrong number of arguments (0 for 2) (ArgumentError)
如果我试图 -
benchmark(func1(index1, array1), index1, array1)
它会输出...
undefined method `func' for main:Object (NoMethodError)
我看到有一个类似的问题是关于Python的,有人问如何将带有参数的函数传递给另一个函数。 传递带有参数的函数到另一个函数中? 需要帮忙吗?谢谢。