如何对Matlab流程进行基准测试? [英] How to benchmark Matlab processes?

查看:282
本文介绍了如何对Matlab流程进行基准测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在寻找如何避免在Matlab代码中使用循环的想法时,我在

Searching for an idea how to avoid using loop in my Matlab code, I found following comments under one question on SE:

自从Matlab ... euhm,R2008a以来,在Matlab中for循环很慢"的说法不再正确了.

The statement "for loops are slow in Matlab" is no longer generally true since Matlab...euhm, R2008a?

您是否已尝试对for循环与现有内容进行基准测试?有时它比矢量化代码要快...

Have you tried to benchmark a for loop vs what you already have? sometimes it is faster than vectorized code...

所以我想问,是否有常用的方法来测试Matlab中进程的速度?用户可以在某个地方看到该过程花费多少时间,或者唯一的方法是将这些过程延长几分钟,以便相互比较时间?

So I would like to ask, is there commonly used way to test the speed of a process in Matlab? Can user see somewhere how much time the process takes or the only way is to extend the processes for several minutes in order to compare the times between each other?

推荐答案

测试MATLAB代码性能的最佳工具是史蒂夫·埃丁斯(Steve Eddins)的timeit函数,

The best tool for testing the performance of MATLAB code is Steve Eddins' timeit function, available here from the MATLAB Central File Exchange.

它为您处理了许多与基准测试MATLAB代码有关的细微问题,例如:

It handles many subtle issues related to benchmarking MATLAB code for you, such as:

  • 通过将基准代码包装在函数中来确保使用JIT编译
  • 热身代码
  • 多次运行代码并求平均值

更新:从R2013b版本开始, timeit 是核心MATLAB的一部分.

Update: As of release R2013b, timeit is part of core MATLAB.

更新:从R2016a版本开始,MATLAB还包括性能测试框架,它以与timeit类似的方式为您解决上述问题.

Update: As of release R2016a, MATLAB also includes a performance testing framework that handles the above issues for you in a similar way to timeit.

这篇关于如何对Matlab流程进行基准测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆