问题描述:

I want to compare the execution time for mathematical equations for different dynamic, interpreted programming languages like Ruby, Perl, and Python.

In Python, there is the convenient timeit module, which allows me to time, where I can simply time for, e.g., a least squares fit (python_lstsqr(x,y)) via

min(timeit.Timer('python_lstsqr(x, y)',

'from __main__ import python_lstsqr, x, y')\

.repeat(repeat=3, number=1000))

(here the best of 3 repetitions and 1000 loops per repetition)

Are there equivalents in Perl and Ruby?

网友答案:

Good old time ?

For Perl, you can use built-in Benchmark or Time::Stopwatch.

For Ruby, the built-in benchmark is good enough.

相关阅读:
Top