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)
|
||||
{
|
||||
_profileTime += TickCount - _profileStart;
|
||||
_profileTime += Stopwatch.GetTimestamp() - _profileStart;
|
||||
}
|
||||
|
||||
_profileStart = _profiling ? TickCount : 0;
|
||||
_profileStart = _profiling ? Stopwatch.GetTimestamp() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Server.Items;
|
||||
|
|
@ -119,17 +120,19 @@ namespace Server.Commands
|
|||
return;
|
||||
}
|
||||
|
||||
var time = Core.Now;
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
var built = BuildObjects(from, type, start, end, args, props, packs, outline, mapAvg);
|
||||
|
||||
if (built > 0)
|
||||
{
|
||||
watch.Stop();
|
||||
from.SendMessage(
|
||||
"{0} object{1} generated in {2:F1} seconds.",
|
||||
"{0} object{1} generated in {2:F2} seconds.",
|
||||
built,
|
||||
built != 1 ? "s" : "",
|
||||
(Core.Now - time).TotalSeconds
|
||||
watch.Elapsed.TotalSeconds
|
||||
);
|
||||
}
|
||||
else
|
||||
|
|
@ -141,7 +144,7 @@ namespace Server.Commands
|
|||
public static void FixSetString(ref string[] args, int index)
|
||||
{
|
||||
var old = args;
|
||||
args = new string[index];
|
||||
args = GC.AllocateUninitializedArray<string>(index);
|
||||
|
||||
Array.Copy(old, 0, args, 0, index);
|
||||
}
|
||||
|
|
@ -149,7 +152,7 @@ namespace Server.Commands
|
|||
public static void FixArgs(ref string[] 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Server.Items;
|
||||
using Server.PathAlgorithms;
|
||||
using Server.PathAlgorithms.FastAStar;
|
||||
|
|
@ -71,18 +72,18 @@ namespace Server
|
|||
{
|
||||
OverrideAlgorithm = alg;
|
||||
|
||||
var start = DateTime.UtcNow.Ticks;
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
var path = new MovementPath(from, new Point3D(p));
|
||||
var end = DateTime.UtcNow.Ticks;
|
||||
var len = Math.Round((end - start) / 10000.0, 2);
|
||||
watch.Stop();
|
||||
|
||||
if (!path.Success)
|
||||
{
|
||||
from.SendMessage("{0} path failed: {1}ms", name, len);
|
||||
from.SendMessage("{0} path failed: {1}ms", name, watch.ElapsedMilliseconds);
|
||||
}
|
||||
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 y = from.Y;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue