Added the command line argument -usehrt to enable high resolution timing on supported platforms (QueryPerformanceCounter)
Timing will fallback to DateTime.UtcNow.Ticks when QPC is unsupported.
This commit is contained in:
parent
473751297d
commit
a5b7e6c78c
1 changed files with 16 additions and 7 deletions
|
|
@ -129,18 +129,22 @@ namespace Server
|
||||||
private static readonly bool _HighRes = Stopwatch.IsHighResolution;
|
private static readonly bool _HighRes = Stopwatch.IsHighResolution;
|
||||||
private static readonly double _Frequency = 1000.0 / Stopwatch.Frequency;
|
private static readonly double _Frequency = 1000.0 / Stopwatch.Frequency;
|
||||||
|
|
||||||
|
private static bool _UseHRT;
|
||||||
|
|
||||||
|
public static bool UsingHighResolutionTiming { get { return _UseHRT && _HighRes && !m_Unix; } }
|
||||||
|
|
||||||
public static long TickCount {
|
public static long TickCount {
|
||||||
get {
|
get {
|
||||||
long t = 0;
|
|
||||||
#if !MONO
|
#if !MONO
|
||||||
// TODO: Unreliable with certain system configurations.
|
if (_UseHRT && _HighRes)
|
||||||
if (_HighRes)
|
{
|
||||||
|
long t = 0;
|
||||||
SafeNativeMethods.QueryPerformanceCounter(out t);
|
SafeNativeMethods.QueryPerformanceCounter(out t);
|
||||||
|
return (long)((double)t * _Frequency);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
t = DateTime.UtcNow.Ticks;
|
return (long)((double)DateTime.UtcNow.Ticks * 0.0001);
|
||||||
|
|
||||||
return (long)((double)t * _Frequency);
|
|
||||||
|
|
||||||
/* We don't really need this, but it may be useful in the future.
|
/* We don't really need this, but it may be useful in the future.
|
||||||
uint t = (uint)Environment.TickCount;
|
uint t = (uint)Environment.TickCount;
|
||||||
|
|
@ -450,6 +454,8 @@ namespace Server
|
||||||
m_HaltOnWarning = true;
|
m_HaltOnWarning = true;
|
||||||
else if ( Insensitive.Equals( args[i], "-vb" ) )
|
else if ( Insensitive.Equals( args[i], "-vb" ) )
|
||||||
m_VBdotNET = true;
|
m_VBdotNET = true;
|
||||||
|
else if (Insensitive.Equals(args[i], "-usehrt"))
|
||||||
|
_UseHRT = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
@ -516,6 +522,9 @@ namespace Server
|
||||||
if ( GCSettings.IsServerGC )
|
if ( GCSettings.IsServerGC )
|
||||||
Console.WriteLine("Core: Server garbage collection mode enabled");
|
Console.WriteLine("Core: Server garbage collection mode enabled");
|
||||||
|
|
||||||
|
if (_UseHRT)
|
||||||
|
Console.WriteLine("Core: Requested high resolution timing ({0})", UsingHighResolutionTiming ? "Supported" : "Unsupported");
|
||||||
|
|
||||||
Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name, RandomImpl.IsHardwareRNG ? "Hardware" : "Software");
|
Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name, RandomImpl.IsHardwareRNG ? "Hardware" : "Software");
|
||||||
|
|
||||||
while( !ScriptCompiler.Compile( m_Debug, m_Cache ) )
|
while( !ScriptCompiler.Compile( m_Debug, m_Cache ) )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue