diff --git a/src/Microsoft.ML.Core/Data/ProgressReporter.cs b/src/Microsoft.ML.Core/Data/ProgressReporter.cs index 0c31e12079..384e1bfb61 100644 --- a/src/Microsoft.ML.Core/Data/ProgressReporter.cs +++ b/src/Microsoft.ML.Core/Data/ProgressReporter.cs @@ -359,7 +359,7 @@ public CalculationInfo(int index, string name, ProgressChannel channel) Index = index; Name = name; PendingCheckpoints = new ConcurrentQueue>(); - StartTime = DateTime.Now; + StartTime = DateTime.UtcNow; Channel = channel; } } @@ -584,7 +584,7 @@ public ProgressEvent(int index, string name, DateTime startTime, ProgressEntry e Index = index; Name = name; StartTime = startTime; - EventTime = DateTime.Now; + EventTime = DateTime.UtcNow; Kind = EventKind.Progress; ProgressEntry = entry; } @@ -597,7 +597,7 @@ public ProgressEvent(int index, string name, DateTime startTime, EventKind kind) Index = index; Name = name; StartTime = startTime; - EventTime = DateTime.Now; + EventTime = DateTime.UtcNow; Kind = kind; ProgressEntry = null; } diff --git a/src/Microsoft.ML.Data/Utilities/TimerScope.cs b/src/Microsoft.ML.Data/Utilities/TimerScope.cs index c196d08a95..5170a25ae6 100644 --- a/src/Microsoft.ML.Data/Utilities/TimerScope.cs +++ b/src/Microsoft.ML.Data/Utilities/TimerScope.cs @@ -46,7 +46,7 @@ public void Dispose() // REVIEW: This is \n\n is to prevent changes across bunch of baseline files. // Ideally we should change our comparison method to ignore empty lines. - _ch.Info("{0}\t Time elapsed(s): {1}\n\n", DateTime.Now, elapsedSeconds); + _ch.Info("{0}\t Time elapsed(s): {1}\n\n", DateTime.UtcNow, elapsedSeconds); using (var pipe = _host.StartPipe("TelemetryPipe")) { diff --git a/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs b/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs index abf1be3697..5758e619cb 100644 --- a/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs +++ b/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; namespace Microsoft.ML.Runtime.FastTree.Internal { @@ -164,7 +165,7 @@ public unsafe void SetTreeScores(int idx, double[] scores) private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel) { - DateTime startTime = DateTime.Now; + Stopwatch stopWatch = Stopwatch.StartNew(); if (maxAllowedFeaturesPerModel < 0) { @@ -450,8 +451,8 @@ private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel) // First lambda was infinity; fixing it fit.Lambdas[0] = Math.Exp(2 * Math.Log(fit.Lambdas[1]) - Math.Log(fit.Lambdas[2])); - TimeSpan duration = DateTime.Now - startTime; - ch.Info("Elapsed time for compression: {0}", duration); + stopWatch.Stop(); + ch.Info("Elapsed time for compression: {0}", stopWatch.Elapsed); return fit; } diff --git a/src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs b/src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs index fd9a2fe7dd..0c75b2dd18 100644 --- a/src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs +++ b/src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs @@ -193,7 +193,7 @@ public string ToTreeEnsembleIni(FeaturesToContentMap fmap, protected int AppendComments(StringBuilder sb, string trainingParams) { - sb.AppendFormat("\n\n[Comments]\nC:0=Regression Tree Ensemble\nC:1=Generated using FastTree\nC:2=Created on {0}\n", DateTime.Now); + sb.AppendFormat("\n\n[Comments]\nC:0=Regression Tree Ensemble\nC:1=Generated using FastTree\nC:2=Created on {0}\n", DateTime.UtcNow); string[] trainingParamsList = trainingParams.Split(new char[] { '\n' }); int i = 0; diff --git a/src/Microsoft.ML.Maml/MAML.cs b/src/Microsoft.ML.Maml/MAML.cs index 718366d576..3f5b5db50a 100644 --- a/src/Microsoft.ML.Maml/MAML.cs +++ b/src/Microsoft.ML.Maml/MAML.cs @@ -145,7 +145,7 @@ internal static int MainCore(TlcEnvironment env, string args, bool alwaysPrintSt Path.GetTempPath(), "TLC"); var dumpFilePath = Path.Combine(dumpFileDir, - string.Format(CultureInfo.InvariantCulture, "Error_{0:yyyyMMdd_HHmmss}_{1}.log", DateTime.Now, Guid.NewGuid())); + string.Format(CultureInfo.InvariantCulture, "Error_{0:yyyyMMdd_HHmmss}_{1}.log", DateTime.UtcNow, Guid.NewGuid())); bool isDumpSaved = false; try { diff --git a/src/Microsoft.ML.ResultProcessor/ResultProcessor.cs b/src/Microsoft.ML.ResultProcessor/ResultProcessor.cs index 731e49fdd4..71244b6536 100644 --- a/src/Microsoft.ML.ResultProcessor/ResultProcessor.cs +++ b/src/Microsoft.ML.ResultProcessor/ResultProcessor.cs @@ -584,7 +584,7 @@ private static bool ValidateMamlOutput(string filename, string[] rawLines, out L Results = runResults, PerFoldResults = foldResults, Time = 0, - ExecutionDate = DateTime.Now.ToString() + ExecutionDate = DateTime.UtcNow.ToString() }; } diff --git a/src/Microsoft.ML.StandardLearners/Standard/Online/OnlineLinear.cs b/src/Microsoft.ML.StandardLearners/Standard/Online/OnlineLinear.cs index 97c88a059b..253800171d 100644 --- a/src/Microsoft.ML.StandardLearners/Standard/Online/OnlineLinear.cs +++ b/src/Microsoft.ML.StandardLearners/Standard/Online/OnlineLinear.cs @@ -206,7 +206,7 @@ protected virtual void InitCore(IChannel ch, int numFeatures, LinearPredictor pr Contracts.Assert(Iteration == 0); Contracts.Assert(Bias == 0); - ch.Trace("{0} Initializing {1} on {2} features", DateTime.Now, Name, numFeatures); + ch.Trace("{0} Initializing {1} on {2} features", DateTime.UtcNow, Name, numFeatures); NumFeatures = numFeatures; // We want a dense vector, to prevent memory creation during training @@ -253,13 +253,13 @@ protected virtual void BeginIteration(IChannel ch) Iteration++; NumIterExamples = 0; - ch.Trace("{0} Starting training iteration {1}", DateTime.Now, Iteration); + ch.Trace("{0} Starting training iteration {1}", DateTime.UtcNow, Iteration); // #if OLD_TRACING // REVIEW: How should this be ported? if (Iteration % 20 == 0) { Console.Write('.'); if (Iteration % 1000 == 0) - Console.WriteLine(" {0} \t{1}", Iteration, DateTime.Now); + Console.WriteLine(" {0} \t{1}", Iteration, DateTime.UtcNow); } // #endif } @@ -269,7 +269,7 @@ protected virtual void FinishIteration(IChannel ch) Contracts.Check(NumIterExamples > 0, NoTrainingInstancesMessage); ch.Trace("{0} Finished training iteration {1}; iterated over {2} examples.", - DateTime.Now, Iteration, NumIterExamples); + DateTime.UtcNow, Iteration, NumIterExamples); ScaleWeights(); #if OLD_TRACING // REVIEW: How should this be ported? @@ -378,7 +378,7 @@ protected virtual void ProcessDataInstance(IChannel ch, ref VBuffer feat, if (_numIterExamples % 5000000 == 0) { Host.StdOut.Write(" "); - Host.StdOut.Write(DateTime.Now); + Host.StdOut.Write(DateTime.UtcNow); } Host.StdOut.WriteLine(); }