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

How do I translate function from Java to C?

We've been asked to build a library of random letters in Java. I did the homework. We are asked to write in C now. I did it with nanotime in Java. I did a little research, and I couldn't find nanotime in C. Already tried in C: (It didn't…
Muhammet Ömer
  • 145
  • 1
  • 11
0
votes
1 answer

How do I accurately predict time using nanoTime?

Built this simple program that just tracks when one pixel changes to white and records the delay + 100ms. Execution time of the simple task on a i9 workstation desktop with high specs returns a delay of 11ms. What can I do to achieve maybe a delay…
jon_woot
  • 21
  • 3
0
votes
0 answers

Time how long a function runs (short duration)

I'm relatively new to Java programming, and I'm running into an issue calculating the amount of time it takes for a function to run. First some background - I've got a lot of experience with Python, and I'm trying to recreate the functionality of…
Luke
  • 26
  • 6
0
votes
0 answers

Java System.nanoTime() multiple parallel calls lead to same values?

public static void main(String[] args) { Map map = IntStream.range(0, 1_000_000) .parallel() .mapToObj(i -> System.nanoTime()) .collect(Collectors.groupingBy(x -> x, Collectors.counting())); …
Michele Mariotti
  • 7,372
  • 5
  • 41
  • 73
0
votes
2 answers

Is System.nanoTime(); or System.currentTimeMillis(); better for a game

In a game loop everyone uses System.nanoTime() but for something like animations, the speed of something, etc some people use System.currentTimeMillis() and some use System.nanoTime(). Which one should I be using?
user8492997
0
votes
1 answer

Datetime pattern with nanoseconds on Log4j

I am trying to set up logging to JSON file and I need nanoseconds to be logged. However when I try the next structure
Tatiana Goretskaya
  • 536
  • 10
  • 25
0
votes
2 answers

Convert a time to nanoseconds in Ruby

I have the following time format: require 'time' input = "2016-10-04_00.50.31.147" format = "%Y-%m-%d_%H.%M.%S.%N" time = Time.strptime(input, format) How do I get the number of nanoseconds since the epoch?
Marco
  • 15,101
  • 33
  • 107
  • 174
0
votes
1 answer

System.nanoTime() returns continuously decreasing times over several runs of QuickSort, how?

I implemented a a standard quicksort algorithm and tested it over several runs and stored the running times in an array. int max = 100; int runs = 1000; int[] arr = new int[max]; Long[] times = new Long[runs]; while(n < runs){ for(int i…
0
votes
0 answers

What kind of number is that?

after doing a benchmark with HdrHistogram i got this number as value: 142.22182267674.623 That should be Nanoseconds but what kind of number is that? Value Percentile TotalCount 1/(1-Percentile) 1382023.167 …
manuel
  • 1,127
  • 1
  • 8
  • 15
0
votes
1 answer

measuring a java program runtime using asm Instrumantation

I was wondering if there is a way to measure a given bytecode (class file , that has main function in the original code) runtime using java bytecode instrumentation of asm. The measure should be as accurate as possible , and if possible in…
RanZilber
  • 1,840
  • 4
  • 31
  • 42
0
votes
1 answer

How to keep track of the elapsed time in a tick method?

In a tick() method, you can't have an int startTime = System.nanoTime() because it will constantly be updating it. I need to find the elapsed time within the tick method, so that every 2 seconds a new object gets spawned. public void tick() { …
badProgrammer
  • 17
  • 1
  • 12
0
votes
2 answers

Calculating for time difference using nanoTime() but getting a negative number

Here is my code in my main that calculates for the time difference of selectionSort() using nanoTime(): System.out.println("Start time :: " + test.start()); test.selectionSort(); System.out.println("End time :: " + test.end()); …
Phillip
  • 21
  • 6
0
votes
1 answer

Get time object from nano second?

I have a nanosecond integer need to be formated as Time object in ruby. How can i get Time object from nanosecond in ruby ? I tried Time.strptime '2318482693000', '%N' but the time returned is current time not the exact time given (in nanoseconds)
Yana Agun Siswanto
  • 1,932
  • 18
  • 30
0
votes
1 answer

get how many seconds this thread ran

hey i have this function in my code: public synchronized void finished() { howManyDone++; log.append("Finished creating board "+this.howManyDone+"\n"); if(howManyDone == boards.length) JOptionPane.showMessageDialog(log, "All…
0
votes
1 answer

System.nanoTime() seems broken. Alternative to check for code efficiency wanted

Since I wanted to check several methods (foo(int)) for efficiency and compare them to the overall runtime I ended up writing something similar to: void testNanoTime(){ long methodDuration = 0; long testStart = System.nanoTime(); for(int…
ctst
  • 1,610
  • 1
  • 13
  • 28