开发者

Where to code this heuristic?

I want to ask a complex question.

I have to code a heuristic for my thesis. I need followings:

  • Evaluate some integral functions
  • Minimize functions over an interval
  • Do this over thousand and thousand times.

So I need a faster programming language to do these jobs. Which language do you suggest? First, I started with Java, but taking integrals become a problem. And I'm not sure about speed.

Connecting Java and other softwares like MATLAB may be a good idea. Since I'm not sure, I want to take your opinions.

Thanks!开发者_StackOverflow


C,Java, ... are all Turing complete languages. They can calculate the same functions with the same precision. If you want achieve performance goals use C that is a compiled and high performances language . Can decrease your computation time avoiding method calls and high level features present in an interpreted language like Java.

Anyway remember that your implementation may impact the performances more than which language you choose, because for increasing input dimension is the computational complexity that is relevant ( http://en.wikipedia.org/wiki/Computational_complexity_theory ).


It's not the programming language, it's probably your algorithm. Determine the big0 notation of your algorithm. If you use loops in loops, where you could use a search by a hash in a Map instead, your algorithm can be made n times faster.

Note: Modern JVM's (JDK 1.5 or 1.6) compile Just-In-Time natively (as in not-interpreted) to a specific OS and a specific OS version and a specific hardware architecture. You could try the -server to JIT even more aggressively (at the cost of an even longer initialization time).

Do this over thousand and thousand times.

Are you sure it's not more, something like 10^1000 instead? Try accurately calculating how many times you need to run that loop, it might surprise you. The type of problems on which heuristics are used, tend to have a really big search space.


Before you start switching languages, I'd first try to do the following things:

  1. Find the best available algorithms.
  2. Find available implementations of those algorithms usable from your language. There are e.g. scientific libraries for Java. Try to use these libraries.
  3. If they are not fast enough investigate whether there is anything to be done about it. Is your problem more specific than what the library assumes. Are you able to improve the algorithm based on that knowledge.
  4. What is it that takes so much/memory? Is this realy related to your language? Try to avoid observing JVM start times instead of the time it performed calculation for you.
  5. Then, I'd consider switching languages. But don't expect it to be easy to beat optimized third party java libraries in c.


Order of the algorithm

Tipically switching between languages only reduce the time required by a constant factor. Let's say you can double the speed using C, but if your algorithm is O(n^2) it will take four times to process if you double the data no matter the language.

And the JVM can optimize a lot of things getting good results.

Some posible optimizations in Java

If you have functions that are called a lot of times make them final. And the same for entire classes. The compiler will know that it can inline the method code, avoiding creating method-call stack frames for that call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜