• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

any segestions or codes

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic