File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes make program faster Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "make program faster" Watch "make program faster" New topic
Author

make program faster

omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
Hi, i have an algo that will be running for a long long time, it's doing a lot of tests, and calling a lot of functions..
how can i make it run faster?
do i write the code of the function in my algo or leave it as methodes and call them from my algo?
is there any tips "document that i might refer to" on how to make my program faster and less consuming of time?
thanks guys
bili
Denis Gurchenkov
Greenhorn

Joined: Sep 28, 2005
Posts: 1
Use a profiler to find hot (frequently executed) parts of your code, and then think how to rewrite them.

Generally, it is NOT recommended to care too much about performance when writing code. First, design, implement and test your code, and only then, think about performance, profile and fix hot spots.

The reason for "write first, care about performance second" is because on most applicaitons, 90% of code constitute only 10% of execution time. So, there is no need to worry about efficiency of those 90% of code.

You can also use "java -server" to run your program. Also, you can try other JVMs, such as BEA JRockit or Excelsior JET, for they run faster _some_ applications.

Deos this answer your question?

Denis
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
thanks Denis for ur fast reply
the thing is that my code will take almost 25 hours :S
-big problem- so i'm searching for ways to minimise that time,
thanks again
bili
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

The advice to profile is generally good; but first, you have to have tried to design an efficient program. For example, no amount of profiling will help you make a slow sorting algorithm into a fast one.

Let's talk about what your program does, and about the algorithm it uses. Perhaps we can come up with a faster way to do the same thing.


[Jess in Action][AskingGoodQuestions]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
The web has a huge amount of information on Java performance tuning, but like Ernest said, we need to know a bit more about what the program does. Sometimes a simple algorithm change or JVM environment change can make an astronomical difference in program speed.

Bill


Java Resources at www.wbrogden.com
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
well guys.. humm
1- there is a function that returns a certain value, i dont know what does it do exactly (i dont have the code of the class) i just use it (it's based on the game theory -Nash-)
2- this call will have to be done on all the combinations of 10 issues => 1024
3- there is 10 tactic => 10 * 1024
4- each tactic might contain from 1 -> 25 winning coalition =>
10 * 25 * 1024
this is the number of calls for the function!!
it's an exhaustive search
anyways i was just searching for tricks on how to improve the algo. (if i should call functions of put the function code in the same algo??)
Best,
Bili
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Let's get our terms straight: the word "algorithm" (I'm assuming "algo" is an abbreviation for "algorithm") refers to the set of steps you go through to solve a problem. So saying "exhaustive search" is a statement of your algorithm. Details like whether a function is inlined, or called separately, are part of the the implementation, not part of the algorithm.

The biggest performance gains always come from improving your algorithm. Fiddly little implementation details rarely make much difference at all.

So I see two possible ways to go forward: first, is there any heuristic you can use to avoid making some of the calls? For example, are certain calls always going to return 1 or 0 or some other known value? In that case, you might speed things up by simply not making those calls.

Second: you should try to obtain the source code for this function, and have a look. Perhaps it's doing more work than necessary for your situation.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10929
    
  12

This is not my field, and Ernest is much more knowlegable than me, but a few things come to mind after reading his last post.

can you tell after making some of the calls that that branch is dead? in other words, you make a call with 1 coalition and one tactic, and get some value... can you from this determing that the other 1023 issue combinations are pointless to check?

also, the profiler here might really help. if 10% of the time is spent in your code making the calls, and 90% is INSIDE that code you don't have, i don't think there is much you can do.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jayesh Lalwani
Ranch Hand

Joined: Nov 05, 2004
Posts: 502
How long is each call to the game theory function taking? Is it taking 300ms or so?

If yes, then you might want to look into optimizing the game theory function or reducing the number of times the game theory function gets called.

If no, then the logic for generating 250 thousand coaliton-tactic-issue combinations might need to be optimized.
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
thanks guy, and yes Jayesh is right,
the only way is to reduce the number of the game theory function calling, for it's taking a lot of time to execute.
Best
Bili
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
You may be embarking on a long journey of discovery here. Optimization of some complex function has been the subject of MUCH work over the history of computing. For example, optimizing lens design was an early sucess story, you also get such mundane applications as minimizing the cost of sausage components.

You present program appears to be exploring the entire parameter space to find the best solution. It may be that a "close to the best" solution could be found much more quickly. Much ingenuity has gone into this sort of thing - my favorite (for sheer coolness) involves genetic algorithms.

Let us know how it goes! Sounds like fun.
Bill
 
 
subject: make program faster
 
Similar Threads
Loading a page
Best ways to handle multithreading
Fun reviewing books
Simple GUI for math programs
arraylist toarray performance