Menu
  • HOME
  • TAGS

system can not handle events fired on nanoseconds, why?

java,timer,timertask,nanotime

The api documentation on System.nanoTime() says: This method provides nanosecond precision, but not necessarily nanosecond resolution (that is, how frequently the value changes) - no guarantees are made except that the resolution is at least as good as that of currentTimeMillis(). As such, the JVM might not be able to...

Why insertion into empty ArrayList takes more time than insertion into non-empty ArrayList?

java,arraylist,nanotime

The difference comes because of the instance creation (new Item()). long stime = System.nanoTime(); //Start Time list.add(new Item(id, "A")); // at this point two things are happening // creation of instance & addition into ArrayList // both takes their own time. long elapsedTime = System.nanoTime() - stime; //Elapsed time The...

Measuring the duration of a selection sort for-loop

java,arrays,for-loop,selection-sort,nanotime

The duration could be stored as a double: Random random = new Random(); int [] array = new int[100000]; for (int i = 0; i < array.length; i++) { array[i] = random.nextInt(1000); } //Begin timer long startTime = System.nanoTime(); for (int i = 0; i < array.length; i++) { int...

JMeter's nanoThreadSleep Property - How do I use it?

performance,jmeter,benchmarking,jmeter-plugins,nanotime

Looking at JMeter code, I found the section below to be the one of interest. So basically the background thread is one that sleeps for NANOTHREAD_SLEEP milliseconds and then when it wakes up, it asks the time. This value has to stay as high as possible not to add to...

1000000000 nanoseconds do not appear to equal a second

java,nanotime

I suggest you print out the value 1000000000 * 30 and check it. You'll find it's wrapping around because it's too big to fit into an integer. In other words, the following program: public class Test { public static void main(String args[]) { System.out.println(1000000000 * 30); System.out.println(1000000000L * 30); }...

Why Java System.timeNano() shows the same time?

java,nanotime

You're seeing all the same number because you're using integer division to convert nanoseconds to milliseconds, which has the effect of dividing it then truncating off any decimal places. Try changing: elapsedTime/1000000 to: elapsedTime/1000000d to get the result including decimal places so you get fractional milliseconds. You can also verify...