You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NET6 - Stopwatch.ElapsedMilliseconds returns wrong result when using monoVM on linux-arm #61599
changed the title [-]NET6 - Stopwatch.ElapsedMilliseconds returns wrong result when using monoVM[/-][+]NET6 - Stopwatch.ElapsedMilliseconds returns wrong result when using monoVM on linux-arm[/+]on Nov 15, 2021
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} - Elapsed {sw.ElapsedMilliseconds}");
but the output is: 2021-11-15 16:45:44.775 - Elapsed 15
You don't have a fractional specifier in your format string, so are you sure the code being run is the code currently written (yes, I've seen your other issue).
Maybe problem is with comething like CurrentCulture/Calendar Ticks per second or something like that.
Unlikely, culture shouldn't be accessed for the stopwatch calculations.
The most likely culprit is that the resolution translation code has an issue (in at least the windows APIs, timers return a tick count and a value giving the resolution).
The other possibility is that whatever clock the stopwatch is using for timings just has a really bad resolution? DateTime(Offset) and StopWatch use different mechanisms to get "time" (since for one you want potentially updated wall-clock time, and for the other you just want an elapsed time), so it's possible that your hardware is providing a poor timing clock. What hardware are you deploying this on?
The other possibility is that whatever clock the stopwatch is using for timings just has a really bad resolution? DateTime(Offset) and StopWatch use different mechanisms to get "time" (since for one you want potentially updated wall-clock time, and for the other you just want an elapsed time), so it's possible that your hardware is providing a poor timing clock. What hardware are you deploying this on?
Device is embedded board with Allwinner H3 board (Nano pi core). I tried it with mono 6.6 which I have on the system also and it seems ok:
Program:
using System;
using System.Diagnostics;
using System.Threading;
namespace StopwatchTestFW
{
internal class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
while (true)
{
sw.Restart();
Thread.Sleep(1);
sw.Stop();
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} - {DateTime.Now.Millisecond}ms - Elapsed {sw.ElapsedMilliseconds} - Total {sw.Elapsed.TotalMilliseconds}");
}
}
}
}
NET5 - ok
NET6 - default runtime - ok
Mono 6.6 & net FW 4.50 Exe - ok
NET6 - MonoVM - bug
Activity
michaldobrodenka commentedon Nov 15, 2021
seems to be fine on win-x64 platform with mono:

[-]NET6 - Stopwatch.ElapsedMilliseconds returns wrong result when using monoVM[/-][+]NET6 - Stopwatch.ElapsedMilliseconds returns wrong result when using monoVM on linux-arm[/+]Clockwork-Muse commentedon Nov 15, 2021
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} - Elapsed {sw.ElapsedMilliseconds}");but the output is:
2021-11-15 16:45:44.775 - Elapsed 15You don't have a fractional specifier in your format string, so are you sure the code being run is the code currently written (yes, I've seen your other issue).
michaldobrodenka commentedon Nov 15, 2021
Sorry, should be:
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} - Elapsed {sw.ElapsedMilliseconds}");To be sure I'm going to retest it.
MichalPetryka commentedon Nov 16, 2021
You probably should use
sw.Elapsed.TotalMilisecondsin order to get more accurate values.michaldobrodenka commentedon Nov 16, 2021
sw.Elapsed.TotalMilisecondsresults are also *100.result (linux-arm, monoVM):
There are about 750 lines per second, so it's about 1-1.5ms for each line, but reported value is between 100-150
michaldobrodenka commentedon Nov 16, 2021
DateTime.Millisecondreturn correct value.Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} - {DateTime.Now.Millisecond}ms - Elapsed {sw.ElapsedMilliseconds} - Total {sw.Elapsed.TotalMilliseconds}");result in:
michaldobrodenka commentedon Nov 16, 2021
Maybe problem is with comething like CurrentCulture/Calendar Ticks per second or something like that.
Clockwork-Muse commentedon Nov 16, 2021
Unlikely, culture shouldn't be accessed for the stopwatch calculations.
The most likely culprit is that the resolution translation code has an issue (in at least the windows APIs, timers return a tick count and a value giving the resolution).
The other possibility is that whatever clock the stopwatch is using for timings just has a really bad resolution?
DateTime(Offset)andStopWatchuse different mechanisms to get "time" (since for one you want potentially updated wall-clock time, and for the other you just want an elapsed time), so it's possible that your hardware is providing a poor timing clock. What hardware are you deploying this on?michaldobrodenka commentedon Nov 16, 2021
Device is embedded board with Allwinner H3 board (Nano pi core). I tried it with mono 6.6 which I have on the system also and it seems ok:
Program:
NET5 - ok
NET6 - default runtime - ok
Mono 6.6 & net FW 4.50 Exe - ok
NET6 - MonoVM - bug
michaldobrodenka commentedon Nov 17, 2021
Problem is already in Ticks:
So 1.4ms - 1432875Ticks
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} - {DateTime.Now.Millisecond}ms - Elapsed {sw.ElapsedMilliseconds} - Total {sw.Elapsed.TotalMilliseconds} - in ticks {sw.ElapsedTicks}");We don't support armel in dotnet - only Tizen does, and that's CoreCLR