fix(core): Fixes date time uses by using stop watch (#549)
- [X] Replaces measurements with stop watch - [X] Some cleanup
This commit is contained in:
parent
6c4308bce6
commit
76970325a3
3 changed files with 17 additions and 13 deletions
|
|
@ -97,15 +97,15 @@ namespace Server
|
||||||
|
|
||||||
if (_profileStart > 0)
|
if (_profileStart > 0)
|
||||||
{
|
{
|
||||||
_profileTime += TickCount - _profileStart;
|
_profileTime += Stopwatch.GetTimestamp() - _profileStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
_profileStart = _profiling ? TickCount : 0;
|
_profileStart = _profiling ? Stopwatch.GetTimestamp() : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimeSpan ProfileTime =>
|
public static TimeSpan ProfileTime =>
|
||||||
TimeSpan.FromMilliseconds(_profileStart > 0 ? _profileTime + (TickCount - _profileStart) : _profileTime);
|
TimeSpan.FromTicks(_profileStart > 0 ? _profileTime + (Stopwatch.GetTimestamp() - _profileStart) : _profileTime);
|
||||||
|
|
||||||
public static Assembly Assembly { get; set; }
|
public static Assembly Assembly { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Server.Items;
|
using Server.Items;
|
||||||
|
|
@ -119,17 +120,19 @@ namespace Server.Commands
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var time = Core.Now;
|
var watch = new Stopwatch();
|
||||||
|
watch.Start();
|
||||||
|
|
||||||
var built = BuildObjects(from, type, start, end, args, props, packs, outline, mapAvg);
|
var built = BuildObjects(from, type, start, end, args, props, packs, outline, mapAvg);
|
||||||
|
|
||||||
if (built > 0)
|
if (built > 0)
|
||||||
{
|
{
|
||||||
|
watch.Stop();
|
||||||
from.SendMessage(
|
from.SendMessage(
|
||||||
"{0} object{1} generated in {2:F1} seconds.",
|
"{0} object{1} generated in {2:F2} seconds.",
|
||||||
built,
|
built,
|
||||||
built != 1 ? "s" : "",
|
built != 1 ? "s" : "",
|
||||||
(Core.Now - time).TotalSeconds
|
watch.Elapsed.TotalSeconds
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -141,7 +144,7 @@ namespace Server.Commands
|
||||||
public static void FixSetString(ref string[] args, int index)
|
public static void FixSetString(ref string[] args, int index)
|
||||||
{
|
{
|
||||||
var old = args;
|
var old = args;
|
||||||
args = new string[index];
|
args = GC.AllocateUninitializedArray<string>(index);
|
||||||
|
|
||||||
Array.Copy(old, 0, args, 0, index);
|
Array.Copy(old, 0, args, 0, index);
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +152,7 @@ namespace Server.Commands
|
||||||
public static void FixArgs(ref string[] args)
|
public static void FixArgs(ref string[] args)
|
||||||
{
|
{
|
||||||
var old = args;
|
var old = args;
|
||||||
args = new string[args.Length - 1];
|
args = GC.AllocateUninitializedArray<string>(args.Length - 1);
|
||||||
|
|
||||||
Array.Copy(old, 1, args, 0, args.Length);
|
Array.Copy(old, 1, args, 0, args.Length);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using Server.Items;
|
using Server.Items;
|
||||||
using Server.PathAlgorithms;
|
using Server.PathAlgorithms;
|
||||||
using Server.PathAlgorithms.FastAStar;
|
using Server.PathAlgorithms.FastAStar;
|
||||||
|
|
@ -71,18 +72,18 @@ namespace Server
|
||||||
{
|
{
|
||||||
OverrideAlgorithm = alg;
|
OverrideAlgorithm = alg;
|
||||||
|
|
||||||
var start = DateTime.UtcNow.Ticks;
|
var watch = new Stopwatch();
|
||||||
|
watch.Start();
|
||||||
var path = new MovementPath(from, new Point3D(p));
|
var path = new MovementPath(from, new Point3D(p));
|
||||||
var end = DateTime.UtcNow.Ticks;
|
watch.Stop();
|
||||||
var len = Math.Round((end - start) / 10000.0, 2);
|
|
||||||
|
|
||||||
if (!path.Success)
|
if (!path.Success)
|
||||||
{
|
{
|
||||||
from.SendMessage("{0} path failed: {1}ms", name, len);
|
from.SendMessage("{0} path failed: {1}ms", name, watch.ElapsedMilliseconds);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
from.SendMessage("{0} path success: {1}ms", name, len);
|
from.SendMessage("{0} path success: {1}ms", name, watch.ElapsedMilliseconds);
|
||||||
|
|
||||||
var x = from.X;
|
var x = from.X;
|
||||||
var y = from.Y;
|
var y = from.Y;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue