What are the most expensive (both in terms of bytecode and cpu cycles) statements in the Java Programming language?
What are the most expensive (both in terms of bytecode and cpu cycles) statements
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In any language, you can find out the speed of various statements by doing them lots of times and seeing how long they take. I’m supposing your question is more intelligent than that. For example, in this scenario, A number of tuning steps were performed, and at each step, something else was the major problem.
First step: major time-taker was the equivalent of incrementing iterators. (Fix? Use integer indexes.)
After fixing that, the problem was building linked lists one element at a time. (Fix? Build them all at once.)
After a redesign, the major problem was allocating and freeing storage for objects. (Fix? Re-use used objects.)
At each stage, some problem is the largest. After fixing that (and getting a good speedup), some other problem is the new largest. After fixing that… (and so on, until you can see what the largest problem is, but you can’t fix it).
You see, it has almost nothing to do with “which statements are most expensive”. If a statement is doing something that you absolutely need done, and you can’t find a better way to do it, then by definition it is the best statement for the job.