为什么str2double这么慢的matlab比较一个mex函数? [英] Why is str2double so slow in matlab as compared to a mex-function?

查看:676
本文介绍了为什么str2double这么慢的matlab比较一个mex函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是标题。


  1. 为什么str2double在MATLAB中比在C / C ++中做的mex函数慢? matlab只是没有好的字符串处理能力?


  2. 任何人都可以给我一些事实的理由,为什么一个mex函数运行这么多的数量级更快?我希望对这个差异做一个运行时间分析,但是我没有任何具体的原因从代码为matlab。


  3. 你能解释一下我如何打开文件,实际看看为内置matlab str2double函数编写的代码?


关于主题:



http://www.mathworks.com/matlabcentral/fileexchange/28893-fast-string-to-double-conversion



我不明白海报意味着什么时,他们试图解释这个功能如何运行更快。例如,这是什么意思:(str2doubleq是在c ++中做的mex函数)



str2doubleq利用mex网关使用c ++快速字符串处理能力和std :: stringstream properties。转换使用了与boost :: lexical_cast中使用的相同的想法



没有人能回答这个问题?

  str2double('123.45e7')
str2double('123 + 45i' )
str2double('3.14159')
str2double('2.7i - 3.14')
str2double({'2.71''3.1415'})
str2double('1,200.34')

2)为什么mex更快?因为当你执行一个标准的m文件脚本,基本上有一个程序,将读取你的程序执行它(一个解释器)。所以有两层。但是,当您编写mex文件时,可以直接使用CPU语言进行编译,以便可以由处理器直接运行。只有一层,所以它的速度更快。有关详情,请参阅维基百科文章:



http ://en.wikipedia.org/wiki/Interpreted_language



http://en.wikipedia.org/wiki/Compiled_language



3)您无法看到str2double的代码,因为它是编译。 Matworks不提供此函数的代码。你可以执行它,但不能读。这对于所有内置函数都是一样的。


my question is the title.

  1. Why is str2double so slow in matlab as compared to a mex function made in C/C++? Does matlab just not have good string handling capabilities?

  2. Can anyone give me some factual reasons as to why a mex function runs so many orders of magnitude faster? I was hoping to do a running time analysis of this difference but I don't have any concrete reasons from the code for matlab.

  3. Can you explain to me how I would open to file and actually look at the code written for the built in matlab str2double function?

some postings on the topic:

http://www.mathworks.com/matlabcentral/fileexchange/28893-fast-string-to-double-conversion

I don't understand what the poster means when they try to explain how this function runs more quickly. For instance, what does this mean: (str2doubleq is the mex function made in c++)

"str2doubleq exploits the mex-gateway to use c++ fast string handling capabilities and the std::stringstream properties. The conversion uses same ideas that is used in boost::lexical_cast"

No one can answer this?

解决方案

1) str2double is a pretty complex function that can convert many different formats. I guess that your mex implementation is much simpler and that can explain why it's faster. Som examples are provided in matlab help:

   str2double('123.45e7')
   str2double('123 + 45i')
   str2double('3.14159')
   str2double('2.7i - 3.14')
   str2double({'2.71' '3.1415'})
   str2double('1,200.34')

2) why mex are faster? Because when you execute a standard m-file script, basically there is a program that will read your program an execute it (an interpreter). So there are two layers. However, when you write a mex-file, you compile it directly in the CPU language, such that it can be run directly by the processor. There is only one layer, so it's faster. For more details, see the wikipedia article:

http://en.wikipedia.org/wiki/Interpreted_language

http://en.wikipedia.org/wiki/Compiled_language

3) You cannot see the code of str2double because it is compiled. Matworks does not provide the code of this function. You can execute it, but not read it. This is the same for all built-in functions.

这篇关于为什么str2double这么慢的matlab比较一个mex函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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