在Matlab中优化打印功能 [英] Optimizing the print function in Matlab

查看:649
本文介绍了在Matlab中优化打印功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我维护一个软件包,可以自动获取数据。原始数据导入时,将绘制并将一些数据图形保存到磁盘。不幸的是, print 函数大大降低了我的性能。



这里是代码性能的细分。

 脚本时间
myscript 9.091s
uichoosefile 3.567s
print 4.178s
legend 0.751s

我的执行时间只有3/4是实际处理时间, print 是这里最大的时间。



里面 print 两行几乎占用了100%的时间

 行代码时间
212 pj = pj = alternatePrintPath(pj); 3.173s
148 drawnow; 0.751s

如何创建 print的优化版本这两条线不是瓶颈吗?简单的优化程序,如降低图形分辨率是不可取的。

解决方案

Matlab实际上是比较特殊的,它很容易优化其内部功能。 我做了 ode15s 在我写的系统生物学建模工具箱中。



这是你自己做的:


  1. 建立一个新的文件夹。我将它称为 image_print

  2. 将该文件夹添加到Matlab路径中,以便在任何地方使用 addpath('image_print')

  3. 将要优化的函数复制到新文件夹 image_print 中,给文件一个新的名字。我将它称为 printimage.m

  4. 在原始函数所在的文件夹中,会有一个名为私有。将该文件夹复制到您的新文件夹 image_print 中。保持名称为 private

现在您可以使用 printimage ,然后优化它,而不是搞乱Matlab的其余部分。实际上有什么帮助将完全取决于您的实际工作流程,并且需要相当的聪明才智。您正在通过使用分析器从正确的位置开始。基本上,你必须通过反复试验找出缓慢的步骤,然后看看是否有更快的方法来专门为你的工作做。原来的功能是非常一般的,所以你可以把整个部分剪掉。不要忘记,你也可以在 private 中修改函数。

奖励建议:因为你只想保存数字到磁盘,你可能要专注于防止他们浪费时间实际绘制到屏幕上。您可能完全注释掉 drawnow 行,但请回报实际发生的事情。


I maintain a software package that automates ingestion of data. When raw data is imported, it is plotted and some graphics of the data are saved to disk. Unfortunately, the print function dramatically slows my performance.

Here is a breakdown of the code performance

Script       Time
myscript     9.091s
uichoosefile 3.567s
print        4.178s
legend       0.751s

Only about 3/4s of my execution time is real processing time and print is the biggest timesink here.

Inside print two lines take up almost 100% of the time

Line Code                                Time
212  pj = pj = alternatePrintPath(pj);   3.173s
148  drawnow;                            0.751s

How can I create an optimized version of print that isn't bottlenecked by these two lines? Simple optimization routines such as lowering graphics resolution are not desirable.

解决方案

Matlab is actually rather special in that it is pretty easy to optimize its internal functions. I did this to ode15s in a systems biology modelling toolbox that I wrote.

This is how you do it yourself:

  1. Make a new folder. I'll call it image_print.
  2. Add that folder to the Matlab path so you can use it anywhere addpath('image_print')
  3. Copy the function you want to optimize into the new folder image_print and give the file a new name. I'll call it printimage.m.
  4. In the folder where the original function was, there will be a folder called private. Copy that folder into your new folder image_print. Keep the name as private.

Now you can use printimage and optimize it without screwing up the rest of Matlab. What actually helps will depend entirely on your actual workflow and require a fair amount of cleverness on your part. You are starting from the right spot by using the profiler. Basically, you'll have to figure out via trial and error what the slow steps are doing and then see if there is a faster way to do it specifically for your work. The original function is very general, so you will be able to cut entire sections out. Don't forget that you can modify the functions in private also.

Bonus suggestion: Because you only want save the figures to disk, you might want to focus on preventing them from wasting time actually drawing to the screen. You might be able to comment out the drawnow line entirely, but please report back on what actually happens.

这篇关于在Matlab中优化打印功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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