nanotime

Centos 7, 400x slower for System.nanoTime than windows

ε祈祈猫儿з 提交于 2021-01-27 02:33:05
问题 I have seen and read posts on why System.nanoTime() is slower on some OSes than others, however I have never seen anything to explain the difference I am seeing now. Using JMH, I am running this benchmark. (Note: it uses System.nanoTime() as well) @Benchmark public long systemNanoTime() { return System.nanoTime(); } On Windows 10, this takes ~25 ns. On Centos 7, Linux 3.10 it is measured as taking ~10293 ns. This is on the same machine, Intel(R) Core(TM) i7-7820X CPU @ 3.60GHz Is there an

(Delta time) Getting 60 updates a second in java

旧时模样 提交于 2020-01-04 04:27:04
问题 I've seen this code several times. long lastTime = System.nanoTime(); final double ticks = 60D; double ns = 1000000000 / ticks; double delta = 0; The code above takes the System time and stores it to lastTime . The 60 ticks should equate to the number of times to update per second. while(running){ long now = System.nanoTime(); delta += (now - lastTime) / ns; lastTime = now; if(delta >= 1){ tick(); delta--; } It takes now and subtracts lastTime , then converts it to nanoseconds/60. Is there

How to get a meaningful result from subtracting 2 nanoTime objects?

扶醉桌前 提交于 2019-12-31 13:17:55
问题 I created a filter that monitors the length of a request. long start = System.nanoTime(); ... long end = System.nanoTime(); How can I get the number of milliseconds from this now? 回答1: (end - start) / 1000000 1 microsecond = 1000 nanoseconds 1 millisecond = 1000 microseconds Note, that the result will be rounded down, but you usually don't get true nanosecond accuracy anyway (accuracy depends on the OS). From the Javadoc on nanoTime() : This method provides nanosecond precision, but not

How can I convert the result of System.nanoTime to a date in Java?

房东的猫 提交于 2019-12-30 06:11:08
问题 I want to convert the result of System.nanoTime() to a date. public void tempBan(Player p, Player banner, int timeInSeconds){ Long timeInNano = (long) (timeInSeconds * 10^9); int newTime = (int) (System.nanoTime() + timeInNano); // here I want to convert newTime to a date } I have converted the seconds into nanoseconds by multiplying by 10^9. Now I need to convert the current system time plus the parameter which I converted into nanoseconds into a date. 回答1: Unfortunately, System.nanoTime()

How to suspend a java thread for a small period of time, like 100 nanoseconds?

余生颓废 提交于 2019-12-17 18:50:13
问题 I know Thread.sleep() can make a java thread suspend for a while, like certain milliseconds and certain nanoseconds. But the problem is the invocation of this function also causes overhead. For example, if I want a thread to suspend for 100 nanoseconds, and I call Thread.sleep(0, 100) . The whole cost for this process is invocation_cost + 100 nanosceonds , which may be much larger the what I want. How could I avoid this problem, and achieve my purpose? The reason I need this is that I want to

Thread.sleep(millisecond) precision [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-13 02:41:06
问题 This question already has answers here : How accurate is Thread.sleep? (3 answers) Closed 3 years ago . Thread.sleep(500) will suspends current thread for at least 500 milliseconds i know it may be little more than 500 but it never less than that. Now 1 millisecond=1000000 nanoseconds I want to suspend current thread for 500 milliseconds i.e.=500*1000000 nanoseconds But when i run the following code it sometimes sleep less than specified value in nanoseconds. Why is this? and how to sleep for

Android: time intervals with deep sleep (System.nanoTime(), System.currentTimeMillis(), SystemClock.elapsedRealtimeNanos())

时光毁灭记忆、已成空白 提交于 2019-12-12 11:38:32
问题 I am implementing an application that has a minimum API level 14 (this is important) and requires consistent interval measuring. No need for ms precision, it just needs to be always counting the time (elapsed seconds). So far, to treat time intervals, I knew these solutions: System.nanoTime() - Works great if Android is running, but stops on deep sleep (this is bad). System.currentTimeMillis() - Good, but not appropriate because it can be changed by the user or by code with

strace java applet

青春壹個敷衍的年華 提交于 2019-12-11 06:14:22
问题 I'm trying to strace a java applet, and strace doesn't seem to be working. I'm calling the following function. public static void testSTrace(){ long c = 0; for (int i = 0; i < 1000; i++){ long start = System.nanoTime(); try{Thread.sleep(0, 100);}catch(Exception e){/*cry*/} long stop = System.nanoTime(); log.info("start : " +start+" stop : "+stop); } } I get the following output from strace just before the above message is called and then nothing from strace: clone(child_stack=0xb7c9f4c4,