Results 1 to 5 of 5
- 03-28-2010, 09:06 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Instrumentation with nanosecond accuracy
Can anyone recommend instrumentation with nanosecond (or as accurate as possible) accuracy. The events I am timing occur in < 1ms, so I know measuring execution time probably isn't the best way to go about this, but it's what I have to work with.
At the moment, I'm using System.nanoTime() and inserting that value into a static array, which leads me to my second question: Can someone give me information on, or point me in the direction of information on, accessing static data structures vs something like a singleton?
Any help greatly appreciated.
- 03-29-2010, 04:22 AM #2
System.nanoTime() is a good start. Depending on the hardware and the OS, the values may report actual times. In other words, one billion nanos will actually represent one second. Otherwise, they should consistently represent some fraction of a second, such as .95 or 1.05. I suggest running a test for one minute using nanoTime() and currentTimeMillis() to get a comparison.
You can access static fields and methods from any object through the Class. Note that Java doesn't do data structures. Access through a singleton requires a reference to the singleton, which is typically obtained through a static method. I suspect the performance difference is minimal.
If you are wanting to collect start and end times for a number of events, you could create a simple class that contains final startNanos and endNanos fields. For each event, get the start and end nanos, pass the values in the constructor, and then store the instance in an ArrayList. This approach allows you to store additional information for each event, such as a description. If you are tracking multiple events, this approach makes sense.The Java Tutorial. Read it.
- 03-29-2010, 01:20 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Thanks for the response Steve.
What you describe is pretty close to my current implementation, so that's reassuring.
By data structures I meant an array / arraylist. I'm currently using a 2 dimensional array storing a number of start and end times. Your addition of a class to store the times and additional detail had crossed my mine, but my concern is the time required to instantiate objects and so on would further skew timings. That probably should be the least of my worries at the minute (considering background processes etc).
Anyway, thanks again. It's good to know that someone else would do something similar to what I have planned.
- 04-01-2010, 06:11 AM #4
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
- 04-02-2010, 02:29 AM #5
Note, too, that I suggested running the instrumented code and collecting the start and end nanos using primitive variables, and then instantiating a class to hold the results. Instrumentation will make the application slightly slower overall, but that approach avoids any impact of the code path being measured.
The Java Tutorial. Read it.
Similar Threads
-
Logic Error: simulated accuracy
By Kaito in forum New To JavaReplies: 3Last Post: 10-27-2009, 01:39 PM -
Dynamic code instrumentation with AspectJ...is it possible ?
By Barronrad in forum New To JavaReplies: 0Last Post: 06-26-2008, 03:27 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks