Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static long nanoTime()
- long startTime = System.nanoTime();
- // ... the code being measured ...
- long estimatedTime = System.nanoTime() - startTime;
- private void test() {
- System.out.println("currentTimeMillis: "+System.currentTimeMillis());
- System.out.println("nanoTime : "+System.nanoTime());
- System.out.println();
- testNano(false); // to sync with currentTimeMillis() timer tick
- for(int xa=0; xa<10; xa++) {
- testNano(true);
- }
- }
- private void testNano(boolean shw) {
- long strMS=System.currentTimeMillis();
- long strNS=System.nanoTime();
- long curMS;
- while((curMS=System.currentTimeMillis()) == strMS) {
- if(shw) { System.out.println("Nano: "+(System.nanoTime()-strNS)); }
- }
- if(shw) { System.out.println("Nano: "+(System.nanoTime()-strNS)+", Milli: "+(curMS-strMS)); }
- }
- long startTimeMillis = System.currentTimeMillis();
- long startTimeNanos = System.nanoTime();
- long currentTimeMillis;
- while((currentTimeMillis = System.currentTimeMillis()) == startTimeMillis) {
- }
- System.out.println(System.nanoTime()-startTimeNanos);
- System.out.println(currentTimeMillis-startTimeMillis);
Add Comment
Please, Sign In to add comment