Wolfram Mathematica中的MATLAB tic toc等效

4nkexdtk  于 7个月前  发布在  Matlab
关注(0)|答案(1)|浏览(74)

我在Mathematica中有一个程序,在MATLAB中有一个等价的程序。我想做一系列的测试来看看他们的比较。为此,我想计算代码的运行时间,为此我使用MATLAB中的tic toc功能。对于Mathematica,我已经尝试使用AbsoluteTiming,但我还没有找到一种方法来实现它在我的整个代码中,只有一个单行。
亲切问候

yrefmtwq

yrefmtwq1#

您可以在评估的开始和结束时使用Now[[1]](假设您希望计算出运行多个单元所需的时间)。

In[1]:= start = Now[[1]];

In[2]:= eval = Table[x^2, {x, 1, 100}];

In[3]:= end = Now[[1]];

In[4]:= end - start

Out[4]= {0, 0, 0, 0, 0, 0.055699}

输出是mathematica计算单元格所用的时间,单位为{年、月、日、小时、分钟、秒}。

相关问题