time-precision

Get time in milliseconds using C#

夙愿已清 提交于 2020-01-11 15:05:04
问题 I'm making a program in which I need to get the time in milliseconds. By time, I mean a number that is never equal to itself, and is always 1000 numbers bigger than it was a second ago. I've tried converting DateTime.Now to a TimeSpan and getting the TotalMilliseconds from that... but I've heard it isn't perfectly accurate. Is there an easier way to do this? 回答1: Use the Stopwatch class. Provides a set of methods and properties that you can use to accurately measure elapsed time. There is

System.currentTimeMillis vs System.nanoTime

喜夏-厌秋 提交于 2019-12-24 14:08:00
问题 Accuracy Vs. Precision What I would like to know is whether I should use System.currentTimeMillis() or System.nanoTime() when updating my object's positions in my game? Their change in movement is directly proportional to the elapsed time since the last call and I want to be as precise as possible. I've read that there are some serious time-resolution issues between different operating systems (namely that Mac / Linux have an almost 1 ms resolution while Windows has a 50ms resolution??). I'm

Set time_t to milliseconds

与世无争的帅哥 提交于 2019-12-24 00:57:58
问题 I have a function and I want the function to stop running once it has been running for a certain number of milliseconds. This function works for seconds but I want to test it for milliseconds. How do I do this? If I set eliminate = 1, it corresponds to 1 second. How do I set eliminate = 5 ms? Function: void clsfy_proc(S_SNR_TARGET_SET pSonarTargetSet, unsigned char *target_num, time_t eliminate) { // get timing time_t _start = time(NULL); time_t _end = _start + eliminate; int _eliminate = 0;

DateTimeOffset resolution in c# and SQL Server

筅森魡賤 提交于 2019-12-23 09:50:04
问题 Docs state that in both .NET and SQL server the resolution is 100ns. The time component of a DateTimeOffset value is measured in 100-nanosecond units called ticks - C# Accuracy - 100 nanoseconds - SQL Server However SQL seems to drop the last digit (e.g. I'm trying to save 2013-08-15 09:19:07.2459675 -04:00, and SQL saves 2013-08-15 09:19:07.2459670 -04:00 - notice the last digit changes.) This happens on a same machine, so its not hardware dependent. Not that I actually need this resolution,

Java ScheduledExecutorService BAD Precision

血红的双手。 提交于 2019-12-07 06:08:43
问题 Hi there i've written a simple program to test the precision of the ScduledExecutorService.schedule() function. The test sets a delay and check the effective distance between the required delay and the effective result. The test have been performed on a i7 machine running Linux 3.8 x86_64, with both OpenJDK 1.7 and Oracle JDK 1.7 The result of the test is really bad, here there is a list to show you the average delta between presumed and effective delay: Legend: Sleep(ms) : the delay required

Storing microseconds in MySQL: which workaround?

做~自己de王妃 提交于 2019-12-05 17:30:22
问题 we're writing a scientific tool with MySQL support. The problem is, we need microsecond precision for our datetime fields, which MySQL doesn't currently support. I see at least two workarounds here: Using a decimal() column type, with integer part corresponding to seconds since some point in time (I doubt that UNIX epoch will do, since we have to store measurements taken in 60's and 50's). Using two integer columns, one for seconds, the other one for microseconds. The most popular query is

Storing microseconds in MySQL: which workaround?

喜你入骨 提交于 2019-12-04 03:14:20
we're writing a scientific tool with MySQL support. The problem is, we need microsecond precision for our datetime fields, which MySQL doesn't currently support. I see at least two workarounds here: Using a decimal() column type, with integer part corresponding to seconds since some point in time (I doubt that UNIX epoch will do, since we have to store measurements taken in 60's and 50's). Using two integer columns, one for seconds, the other one for microseconds. The most popular query is selecting columns corresponding to a time interval (i.e. dt_record > time1 and dt_record < time2). Which

Get time in milliseconds using C#

拥有回忆 提交于 2019-12-02 14:59:36
I'm making a program in which I need to get the time in milliseconds. By time, I mean a number that is never equal to itself, and is always 1000 numbers bigger than it was a second ago. I've tried converting DateTime.Now to a TimeSpan and getting the TotalMilliseconds from that... but I've heard it isn't perfectly accurate. Is there an easier way to do this? Use the Stopwatch class. Provides a set of methods and properties that you can use to accurately measure elapsed time. There is some good info on implementing it here: Performance Tests: Precise Run Time Measurements with System

Is there any way to get current time in nanoseconds using JavaScript?

别来无恙 提交于 2019-11-27 23:25:32
So, I know I can get current time in milliseconds using JavaScript. But, is it possible to get the current time in nanoseconds instead? Jeffrey Yasskin Achieve microsecond accuracy in most browsers using: window.performance.now() See also: https://developer.mozilla.org/en-US/docs/Web/API/Performance.now() http://www.w3.org/TR/hr-time/ Building on Jeffery's answer, to get an absolute time-stamp (as the OP wanted) the code would be: var TS = window.performance.timing.navigationStart + window.performance.now(); result is in millisecond units but is a floating-point value reportedly " accurate to

How precise is the internal clock of a modern PC?

二次信任 提交于 2019-11-27 21:55:53
I know that 10 years ago, typical clock precision equaled a system-tick, which was in the range of 10-30ms. Over the past years, precision was increased in multiple steps. Nowadays, there are ways to measure time intervals in actual nanoseconds. However, usual frameworks still return time with a precision of only around 15ms. My question is, which steps did increase the precision, how is it possible to measure in nanoseconds, and why are we still often getting less-than-microsecond precision (for instance in .NET). (Disclaimer: It strikes me as odd that this was not asked before, so I guess I