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
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?
Joined: Aug 13, 2004
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
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.
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.
Joined: Aug 13, 2004
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
author and iconoclast
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.
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
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.
Joined: Aug 13, 2004
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
Author and all-around good cowpoke
Joined: Mar 22, 2000
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.