Questions tagged [nanotime]

Anything related to programming languages functions (or other similar facilities) allowing the retrieval of the current time with a resolution in the nanoseconds range.

Anything related to programming languages functions (or other similar facilities) allowing the retrieval of the current time with a resolution in the nanoseconds (ns) range.

146 questions
0
votes
1 answer

Calculating Elapse Time

This program will display the start time, end time and elapse time of a program to the user. For example if the program started at 09:23:45 and ended at 09:23:55 then the output to the user would be as such, start time: 09h:23m:45s end time:…
mar
  • 43
  • 1
  • 6
0
votes
1 answer

Java - Convert Nanoseconds to HH/MM/SS

long nanoseconds = System.nanoTime(); long microseconds = nanoseconds / 1000; long miliseconds = microseconds / 1000; long seconds = miliseconds / 1000; long minutes = seconds / 60; long hours = minutes / 60; System.out.println…
Hatefiend
  • 3,416
  • 6
  • 33
  • 74
0
votes
2 answers

Is it reasonable to use System.currentTimeMillis() in conjunction with System.nanoTime()?

Here is my modest proposal: When the JVM starts Call System.currentTimeMillis() and store as starting "wall clock" time: long currentTimeMillis0. Call System.nanoTime() and store as starting "nano" time: long nanoTime0. Throughout the run of the…
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
0
votes
0 answers

What is the reason of having nanoTime 10 times slower than currentTimeMillis?

Consider the following code package tests; public class Test_computer_speed { public static void main(String[] args) { for(int i=0; i<10; ++i) { testMillis(); } for(int i=0; i<10; ++i) { …
Dims
  • 47,675
  • 117
  • 331
  • 600
0
votes
4 answers

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

I ran my profiler program for 1000 iterations to calculate the average time taken to insert into Empty ArrayList and average time to insert into Non-Empty ArrayList. I ran my profiler program for ArrayList, where Item class is class Item{ …
user1612078
  • 555
  • 1
  • 7
  • 22
0
votes
1 answer

System.nanoTime() and other Time-Related Classes

Right now I'm making skills for characters and I wanted to add cooldowns, but I have no idea on how to set times but I think I got an idea on which variables it should have: private long currentTime; <-- this is the actual cooldown private long…
0
votes
1 answer

Android: check value of System.nanoTime

In my app I start a nanoTime in this way: long startTime = System.nanoTime(); now I want that at a specific value of 'startTime' (ex: 1000000) is called a method "myMethod" private void myMethod(){ //all operations } what's the best way to…
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
0
votes
1 answer

Timestamp in milliseconds doesn't gets converted to hours, minutes and seconds properly?

Below is my simple timer class which is working fine in simplest cases. I am using below timer class to measure how much time certain code takes in getting executed. public static class StopTimer { public static StopTimer getInstance() { …
john
  • 11,311
  • 40
  • 131
  • 251
0
votes
3 answers

consecutive coin flip

I apologize in advance for my lack of Java knowledge. I am new to Java programming and am trying to make a program where I can flip a coin and count how many times the coin lands on heads within N amount of rolls, measure the time it takes to do so,…
Bfrank
  • 33
  • 1
  • 4
  • 12
0
votes
0 answers

Java strange behaviour : elapsed time is faster with println

I'm seeing some strange behaviour in Java: Commenting a println makes the function execute slower. Uncommenting the println makes the function execute faster. I would expect this to be reversed, as println should cost time. The trigger is the…
imran
  • 247
  • 2
  • 11
0
votes
1 answer

Using UUID.randomUUID() and calling method multiple times?

For a class assignment I have to compare different lists' performance with one another's using UUID.randomUUID().toString() to insert a few thousand random strings in a list and record how long it takes with the nanoTime() method. I just can't…
Xatyrn
  • 91
  • 7
0
votes
1 answer

Timer loop displaying 0 ticks instead of 60

I have the following code: public void run(){ long lastTime=System.nanoTime(); final double amountOfTicks=60.0; double ns=1000000000/amountOfTicks; double delta=0; int updates=0; int frames=0; long…
Insederec
  • 303
  • 1
  • 3
  • 10
0
votes
1 answer

Could someone explain this description of System.nanoTime()?

This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Differences in successive calls that span greater than approximately 292 years (263 nanoseconds) will not…
user1071840
  • 3,522
  • 9
  • 48
  • 74
0
votes
2 answers

Find time-difference between epoch and current time

I need to find the difference between two time values when one of them is fetched using System. currentTimeMillis() i.e. it's the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC and the other one is…
user1071840
  • 3,522
  • 9
  • 48
  • 74
0
votes
1 answer

measure duration of timer function

I have a timer function (for polling) that I want to call every 1uS but I also want to make sure that there is enough time for other tasks to run so I want to measure the time it takes to execute this function. For that I thought I could use…
stdcerr
  • 13,725
  • 25
  • 71
  • 128
1 2 3
9
10