Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

any segestions or codes  RSS feed

 
nooor nove
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How much does a program cost in terms of time? If we wanted to analyze the cost of a program, we have to figure out the cost each and every statement made in the application program. In your data structure and algorithms courses, you have to analyze the performance of algorithms to know how to construct efficient programs. In there, the main driving factor is the number of multiplications in an algorithm for example. Here, we have to analyze the cost of selecting one program over the other.

Consider the following algorithm to calculate the cost of a program.

The program is prepared to be opened as a file to be modified
Before and after every statement, put statements that read the time in milliseconds
Calculate the cost of the statement by subtracting the times off of each other
Output gathered statistics to application developer

Now, how can we do this with style? Using the JTextArea, we can output three columns as follows: line number �\t� cost in milliseconds �\t� the Java statement; and the last row should output some global statistics. The application developer can then determine the statements that take intensive CPU cycles and begin to consider alternative coding approaches.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"aaaaa aaaaa"
Please don't post the same message in multiple forums. It makes a conversation difficult to follow.

Also, please adjust your display name to match the Naming Policy (basically it should be a legit first and last name).

Lastly -- I'm moving this to the Performance forum, where I think this is a better fit.

Thanks! And welcome to the JavaRanch!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your statement by statement approach is much too detailed - you would drown in numbers - "unable to see the forest for the trees". Furthermore, those time checking statements would totally distort what you are trying to time. Consider the extreme nature of modern CPU optimization using multi-level caches as complicated by the various Java JIT optimizations. Your timing results would be meaningless.

A better approach would be to profile at a method level with a standard benchmark example problem until you can zero in on the expensive operations.
Bill
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One additional suggestion: please use a more speaking subject for the thread. From the current one, I didn't have any idea of what the thread is about - and if I weren't the moderator of this forum, I likely wouldn't even had have opened it.

A good subject line would be something along the lines of "statement level performance analysis". You can change it by hitting the edit button on your very first post in this thread. Thanks!

And welcome at the Ranch, of course - have a lot of fun!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!