我应该选择哪种语言,C或Java? [英] which language should I choose, C or Java?

查看:63
本文介绍了我应该选择哪种语言,C或Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个matlab代码,它包含许多大数字循环(矩阵和向量运算)。它太慢了,我的32 GB RAM现在还不够。我计划将其转换为C或Java。我不熟悉那些语言。能否请你给我一些建议?

Hi, I have a matlab code, which involves many and big number loops (matrix and vector operations). It is too slow and my 32 GB RAM is not enough now. I plan to convert it to C or Java. I am not familiar with those languages. Could you please give me some suggestions which one I should take?

推荐答案

不幸的是,任何人都不会帮助你,至少不会很快帮助你......



Matlab由一群知识渊博的人编写。他们花了很多时间进行优化和内存管理,所以如果你说它很慢,那么把它改成另一种语言,特别是作为一个初学者,不会让它变得更快(可能恰恰相反)。 />


处理大量(内存)集时,复杂的数学经验起着重要作用。一个经验丰富的程序员会知道要寻找什么以及如何管理这些东西,没有经验的人会想念他们而不知道为什么它不起作用。像展开循环,何时内联,指针管理和内存管理等需要多年经验才能掌握。



如果这是你正在做的工作,我会建议找到一个能为你做到这一点的人,但不要指望结果比Matlab可以产生的速度快得多,你可能需要花费数百或数千小时才能看到一位数的百分比增益。
Unfortunately either one is not going to help you, at least not anytime soon...

Matlab is programmed by a team of very knowledgeable people. They put a lot of time into optimizing and memory management, so if you are saying its slow, then changing it over to another language, especially as a beginner, is not going to make it any faster (probably quite the opposite).

When dealing with huge number (memory) sets and complex mathematics experience plays a huge part. An experienced programmer will know what to look for and how to manage those things, an inexperienced one will miss them and not know why its not working. Things like unrolling loops, when to inline, pointer management and memory management take years of experience to master.

If this is something you are doing for work, I would suggest finding somebody who can do this for you, but don't expect the results to be significantly faster than what Matlab can produce, you may spend hundreds or thousands of hours to see a single digit percentage gain.


好吧,MathLab非常强大,因为它是为数学家设计的,它隐藏了所有使数字方法难以实现的好东西。但在通用的同时,它可能在特殊或具体任务上变得缓慢或耗费资源。是的,通常将问题解决方案移植到像C这样的语言会使速度快得多。但这样做通常会非常困难 - 即使对于没有数学问题解决经验的有经验的C程序员也是如此。 Java或C#解决方案有点处于规模中间 - 但你可以找到几个你可以使用的现成数学库。

我一般说。因为它在很大程度上取决于具体问题。

假设你做了一些较小的任务,但很多次,你可以在更短的时间内获得更好的结果;但如果你试图解决复杂的一次性问题......那么......你将不得不面对几个挑战。



想要得到一些想法关于数值方法,请深入了解这本伟大的书: http://www2.units.it /ipl/students_area/imm2/files/Numerical_Recipes.pdf [ ^ ]。好吧,大部分是你在使用MathLab时不必处理的事情。
Well, MathLab is really powerful because it is made for mathematicians and it is hiding all the fine things that make numeric methods hard to implement. But in the same time as it is general, it might get slow or resource-consuming on special or concrete tasks. Yes, in general porting a problem solution to a language like C would make it much-much faster. But doing it would be in general really hard - even for experienced C programmers without experience in mathematical problem solving. Java or C# solutions would be somewhat in the middle of the scale - but you could find several ready-made mathematical libraries you could use.
I said in general. Because it depends much on the concrete problem.
Let's say, if you are doing some smaller task, but many times, you could get better results in a shorter timespan; but if you try to solve a one-time problem that is complicated... well... than you will have to face several challenges.

To get some ideas about numerical methods, have a deeper look in this great book: http://www2.units.it/ipl/students_area/imm2/files/Numerical_Recipes.pdf[^]. Well, most of this is what you don't have to deal with when using MathLab.


在考虑使用其他编程语言进行编码之前,你应该尝试改进你的算法。

如果您已经这样做并且您的算法非常大,那么您可以考虑使用 C ++ Java slowness很有传奇色彩,你可以试试 C#

另一方面,如果算法相对较小,那么 C 编程语言是正确的选择。
Before considering to code with another programming language you should try to improve your algorithms.
If you already did that and your algorithm is quite large then you may consider using C++ (Java slowness is legendary, you might try C# instead).
If, on the other hand, the algorithm is relatively small, then the C programming language is the right choice.


这篇关于我应该选择哪种语言,C或Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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