是否值得从matlab调用java? [英] Is it worth to call java from matlab?

查看:377
本文介绍了是否值得从matlab调用java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于物理项目,我们要分析两个表面(由一堆顶点指定),并计算这些表面之间的体积。为了能够这样做,我们要实现一个二维间隔搜索树。总的渐近运行时间将接近O(n <2> log n)。

For a physics-project, we want to analyze two surfaces (specified by a bunch of vertices) and calculate the volume between those surfaces. To be able to do this, we want to implement a two-dimensional interval-search tree. In total the asymptotic run time, will be close to O(n2log n).

总之,我们要实现一个算法,这将是相当耗时的。此外,该算法没有从matlab中高度优化的数学库中获益。因此,我们正在考虑从matlab调用Java。最后,我们想知道:

In summary we are going to implement an algorithm, which will be quite time-expensive. Furthermore, the algorithm doesn't profit from the highly optimized math libraries in matlab. Therefore, we are considering to call Java from matlab. Conclusively we would like to know:

在什么程度上Java比matlab更快,忽略了matlab中数学库的高度优化的性能?

"To what degree is Java faster than matlab, ignoring the highly optimized performance from the math libraries in matlab?"

从matlab重复调用java方法时有明显的延迟吗?

"Is there any significant delay when repeatedly calling a java method from matlab?"

例如每次调用方法时,JVM必须启动吗?

e.g. does the JVM have to be started every time the method is called? does the jar have to be loaded every single time the method is called?

我希望你们中的一些人能帮我(也许是其他人)这个问题。

I hope some of you could help me (and maybe others) with this question.

推荐答案

如果你决定在MATLAB中编写实现,这里有一些非常好的观点 @ AndrewJanke 在一个很好的答案关于在MATLAB中的OOP性能(值得阅读整篇文章):

If you decide to write the implementation in MATLAB, here are some very good points @AndrewJanke made in an excellent answer regarding OOP performance in MATLAB (worth reading the whole post):


在MATLAB中模拟C ++或Java类可能不是最优的。
Java / C ++类通常是这样构建的,即对象是
最小的构造块,尽可能具体(也就是说,大量的
不同的类),并将它们组成数组,集合
对象等,并用循环遍历它们。要做出快速的MATLAB
类,将这种方法转换出来。有更大的类,其
字段是数组,并在这些数组上调用向量化方法。

Mimicking a C++ or Java class in MATLAB probably won't be optimal. Java/C++ classes are typically built such that objects are the smallest building blocks, as specific as you can (that is, lots of different classes), and you compose them in arrays, collection objects, etc, and iterate over them with loops. To make fast MATLAB classes, turn that approach inside out. Have larger classes whose fields are arrays, and call vectorized methods on those arrays.

关键是安排你的代码发挥的优势b $ b语言 - 数组处理,向量化数学 - 避免弱点。

The point is to arrange your code to play to the strengths of the language - array handling, vectorized math - and avoid the weak spots.

要回答你的问题, :


在MATLAB启动时,MATLAB虚拟地址空间的一部分是由Java虚拟机(JVM)保留的
,用于
存储MATLAB数组。

At MATLAB startup, part of the MATLAB virtual address space is reserved by the Java Virtual Machine (JVM) and cannot be used for storing MATLAB arrays.

所以它只在启动时初始化一次。

so it is only initialized once at startup.

当调用Java方法而不是M文件时,还有一个开销(因为MATLAB类型必须编组到Java数据类型)。

Also there is an overhead when calling Java methods as opposed to M-files (since MATLAB types have to be marshalled to and from Java data types).

现在,如果你想挤出每一个最后的性能,请务必调用Java方法如下:

Now if you want to squeeze out every last bit of performance, make sure to call Java methods as:

func(obj)

而不是:

obj.func()

这篇关于是否值得从matlab调用java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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