From 791444b225bd2d4e38565cbb1d44f3d5459b6743 Mon Sep 17 00:00:00 2001 From: "Sparks, Collin" Date: Fri, 11 May 2018 15:00:53 -0400 Subject: [PATCH 1/6] Removed calls to DateTime.Now The codebase now uses DateTime.UtcNow, instead of DateTime.Now, to be locale agnostic. --- src/Microsoft.ML.Core/Data/ProgressReporter.cs | 6 +++--- src/Microsoft.ML.Data/Utilities/TimerScope.cs | 2 +- .../LassoBasedEnsembleCompressor.cs | 4 ++-- src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs | 2 +- src/Microsoft.ML.Maml/MAML.cs | 2 +- src/Microsoft.ML.ResultProcessor/ResultProcessor.cs | 2 +- .../Standard/Online/OnlineLinear.cs | 10 +++++----- 7 files changed, 14 insertions(+), 14 deletions(-) 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..3a32cf033d 100644 --- a/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs +++ b/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs @@ -164,7 +164,7 @@ public unsafe void SetTreeScores(int idx, double[] scores) private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel) { - DateTime startTime = DateTime.Now; + DateTime startTime = DateTime.UtcNow; if (maxAllowedFeaturesPerModel < 0) { @@ -450,7 +450,7 @@ 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; + TimeSpan duration = DateTime.UtcNow - startTime; ch.Info("Elapsed time for compression: {0}", duration); 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(); } From 030fa6fe7ffb06ebebc7d27421f39039648f1a99 Mon Sep 17 00:00:00 2001 From: "Sparks, Collin" Date: Fri, 11 May 2018 15:32:41 -0400 Subject: [PATCH 2/6] Replaced DateTime reference with UtcDatetime --- src/Microsoft.ML.Core/Data/DateTime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ML.Core/Data/DateTime.cs b/src/Microsoft.ML.Core/Data/DateTime.cs index 52b30b5bb6..d4840f89bd 100644 --- a/src/Microsoft.ML.Core/Data/DateTime.cs +++ b/src/Microsoft.ML.Core/Data/DateTime.cs @@ -201,7 +201,7 @@ public DvDateTimeZone(SysDateTimeOffset dto) // Since it is constructed from a SysDateTimeOffset, all the validations should work. var success = TryValidateOffset(dto.Offset.Ticks, out _offset); Contracts.Assert(success); - _dateTime = ValidateDate(new DvDateTime(dto.DateTime), ref _offset); + _dateTime = ValidateDate(new DvDateTime(dto.UtcDateTime), ref _offset); Contracts.Assert(!_dateTime.IsNA); Contracts.Assert(!_offset.IsNA); AssertValid(); From 058785533acbbdf0e10e71a83819bbba8488df6e Mon Sep 17 00:00:00 2001 From: "Sparks, Collin" Date: Fri, 11 May 2018 16:03:44 -0400 Subject: [PATCH 3/6] Replace DateTime with DateTimeOffset DateTime.UtcNow is now DateTimeOffset.Now.UtcDateTime --- src/Microsoft.ML.Core/Data/DateTime.cs | 2 +- src/Microsoft.ML.Core/Data/ProgressReporter.cs | 6 +++--- src/Microsoft.ML.Data/Utilities/TimerScope.cs | 2 +- .../LassoBasedEnsembleCompressor.cs | 4 ++-- src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs | 2 +- src/Microsoft.ML.InternalStreams/UnbufferedStream.cs | 4 ++-- src/Microsoft.ML.Maml/MAML.cs | 2 +- src/Microsoft.ML.ResultProcessor/ResultProcessor.cs | 2 +- .../Standard/Online/OnlineLinear.cs | 10 +++++----- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.ML.Core/Data/DateTime.cs b/src/Microsoft.ML.Core/Data/DateTime.cs index d4840f89bd..4c2888c7ac 100644 --- a/src/Microsoft.ML.Core/Data/DateTime.cs +++ b/src/Microsoft.ML.Core/Data/DateTime.cs @@ -74,7 +74,7 @@ public DvDateTime Date /// /// Gets a DvDateTime object representing the current UTC date and time. /// - public static DvDateTime UtcNow { get { return new DvDateTime(SysDateTime.UtcNow); } } + public static DvDateTime UtcNow { get { return new DvDateTime(SysDateTimeOffset.Now.UtcDateTime); } } public bool IsNA { diff --git a/src/Microsoft.ML.Core/Data/ProgressReporter.cs b/src/Microsoft.ML.Core/Data/ProgressReporter.cs index 384e1bfb61..2455d899f2 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.UtcNow; + StartTime = DateTimeOffset.Now.UtcDateTime; Channel = channel; } } @@ -584,7 +584,7 @@ public ProgressEvent(int index, string name, DateTime startTime, ProgressEntry e Index = index; Name = name; StartTime = startTime; - EventTime = DateTime.UtcNow; + EventTime = DateTimeOffset.Now.UtcDateTime; 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.UtcNow; + EventTime = DateTimeOffset.Now.UtcDateTime; Kind = kind; ProgressEntry = null; } diff --git a/src/Microsoft.ML.Data/Utilities/TimerScope.cs b/src/Microsoft.ML.Data/Utilities/TimerScope.cs index 5170a25ae6..b9f1187ffd 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.UtcNow, elapsedSeconds); + _ch.Info("{0}\t Time elapsed(s): {1}\n\n", DateTimeOffset.Now.UtcDateTime, 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 3a32cf033d..1ec3c2f784 100644 --- a/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs +++ b/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs @@ -164,7 +164,7 @@ public unsafe void SetTreeScores(int idx, double[] scores) private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel) { - DateTime startTime = DateTime.UtcNow; + DateTime startTime = DateTimeOffset.Now.UtcDateTime; if (maxAllowedFeaturesPerModel < 0) { @@ -450,7 +450,7 @@ 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.UtcNow - startTime; + TimeSpan duration = DateTimeOffset.Now.UtcDateTime - startTime; ch.Info("Elapsed time for compression: {0}", duration); return fit; diff --git a/src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs b/src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs index 0c75b2dd18..e0d091cfb6 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.UtcNow); + sb.AppendFormat("\n\n[Comments]\nC:0=Regression Tree Ensemble\nC:1=Generated using FastTree\nC:2=Created on {0}\n", DateTimeOffset.Now.UtcDateTime); string[] trainingParamsList = trainingParams.Split(new char[] { '\n' }); int i = 0; diff --git a/src/Microsoft.ML.InternalStreams/UnbufferedStream.cs b/src/Microsoft.ML.InternalStreams/UnbufferedStream.cs index 23442d8475..e6c9bd59ed 100644 --- a/src/Microsoft.ML.InternalStreams/UnbufferedStream.cs +++ b/src/Microsoft.ML.InternalStreams/UnbufferedStream.cs @@ -873,11 +873,11 @@ private bool FillBufferPass() { // read into buffer: int readBytes; - //long t = DateTime.UtcNow.Ticks; + //long t = DateTimeOffset.Now.UtcDateTime.Ticks; //long startPos = IOUtil.Win32.Raw.GetFilePos(handle); bool readres = IOUtil.Win32.Raw.ReadFile(_handle, _alignedBuffer[_bufferFillIndex], (int)Math.Min(_blockSize, _alignedLimit - _totalRead), out readBytes); - //t = DateTime.UtcNow.Ticks - t; + //t = DateTimeOffset.Now.UtcDateTime.Ticks - t; //Console.WriteLine("core time: " + (t / (double)TimeSpan.TicksPerSecond).ToString("0.000")); if (!readres) { diff --git a/src/Microsoft.ML.Maml/MAML.cs b/src/Microsoft.ML.Maml/MAML.cs index 3f5b5db50a..24c52b6b88 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.UtcNow, Guid.NewGuid())); + string.Format(CultureInfo.InvariantCulture, "Error_{0:yyyyMMdd_HHmmss}_{1}.log", DateTimeOffset.Now.UtcDateTime, Guid.NewGuid())); bool isDumpSaved = false; try { diff --git a/src/Microsoft.ML.ResultProcessor/ResultProcessor.cs b/src/Microsoft.ML.ResultProcessor/ResultProcessor.cs index 71244b6536..40bc45a691 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.UtcNow.ToString() + ExecutionDate = DateTimeOffset.Now.UtcDateTime.ToString() }; } diff --git a/src/Microsoft.ML.StandardLearners/Standard/Online/OnlineLinear.cs b/src/Microsoft.ML.StandardLearners/Standard/Online/OnlineLinear.cs index 253800171d..9cee00210b 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.UtcNow, Name, numFeatures); + ch.Trace("{0} Initializing {1} on {2} features", DateTimeOffset.Now.UtcDateTime, 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.UtcNow, Iteration); + ch.Trace("{0} Starting training iteration {1}", DateTimeOffset.Now.UtcDateTime, 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.UtcNow); + Console.WriteLine(" {0} \t{1}", Iteration, DateTimeOffset.Now.UtcDateTime); } // #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.UtcNow, Iteration, NumIterExamples); + DateTimeOffset.Now.UtcDateTime, 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.UtcNow); + Host.StdOut.Write(DateTimeOffset.Now.UtcDateTime); } Host.StdOut.WriteLine(); } From da92df9975481eb9692d50bae50f239361b0040e Mon Sep 17 00:00:00 2001 From: "Sparks, Collin" Date: Fri, 11 May 2018 16:26:51 -0400 Subject: [PATCH 4/6] Revert "Replace DateTime with DateTimeOffset" This reverts commit 058785533acbbdf0e10e71a83819bbba8488df6e. --- src/Microsoft.ML.Core/Data/DateTime.cs | 2 +- src/Microsoft.ML.Core/Data/ProgressReporter.cs | 6 +++--- src/Microsoft.ML.Data/Utilities/TimerScope.cs | 2 +- .../LassoBasedEnsembleCompressor.cs | 4 ++-- src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs | 2 +- src/Microsoft.ML.InternalStreams/UnbufferedStream.cs | 4 ++-- src/Microsoft.ML.Maml/MAML.cs | 2 +- src/Microsoft.ML.ResultProcessor/ResultProcessor.cs | 2 +- .../Standard/Online/OnlineLinear.cs | 10 +++++----- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.ML.Core/Data/DateTime.cs b/src/Microsoft.ML.Core/Data/DateTime.cs index 4c2888c7ac..d4840f89bd 100644 --- a/src/Microsoft.ML.Core/Data/DateTime.cs +++ b/src/Microsoft.ML.Core/Data/DateTime.cs @@ -74,7 +74,7 @@ public DvDateTime Date /// /// Gets a DvDateTime object representing the current UTC date and time. /// - public static DvDateTime UtcNow { get { return new DvDateTime(SysDateTimeOffset.Now.UtcDateTime); } } + public static DvDateTime UtcNow { get { return new DvDateTime(SysDateTime.UtcNow); } } public bool IsNA { diff --git a/src/Microsoft.ML.Core/Data/ProgressReporter.cs b/src/Microsoft.ML.Core/Data/ProgressReporter.cs index 2455d899f2..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 = DateTimeOffset.Now.UtcDateTime; + 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 = DateTimeOffset.Now.UtcDateTime; + 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 = DateTimeOffset.Now.UtcDateTime; + 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 b9f1187ffd..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", DateTimeOffset.Now.UtcDateTime, 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 1ec3c2f784..3a32cf033d 100644 --- a/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs +++ b/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs @@ -164,7 +164,7 @@ public unsafe void SetTreeScores(int idx, double[] scores) private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel) { - DateTime startTime = DateTimeOffset.Now.UtcDateTime; + DateTime startTime = DateTime.UtcNow; if (maxAllowedFeaturesPerModel < 0) { @@ -450,7 +450,7 @@ 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 = DateTimeOffset.Now.UtcDateTime - startTime; + TimeSpan duration = DateTime.UtcNow - startTime; ch.Info("Elapsed time for compression: {0}", duration); return fit; diff --git a/src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs b/src/Microsoft.ML.FastTree/TreeEnsemble/Ensemble.cs index e0d091cfb6..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", DateTimeOffset.Now.UtcDateTime); + 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.InternalStreams/UnbufferedStream.cs b/src/Microsoft.ML.InternalStreams/UnbufferedStream.cs index e6c9bd59ed..23442d8475 100644 --- a/src/Microsoft.ML.InternalStreams/UnbufferedStream.cs +++ b/src/Microsoft.ML.InternalStreams/UnbufferedStream.cs @@ -873,11 +873,11 @@ private bool FillBufferPass() { // read into buffer: int readBytes; - //long t = DateTimeOffset.Now.UtcDateTime.Ticks; + //long t = DateTime.UtcNow.Ticks; //long startPos = IOUtil.Win32.Raw.GetFilePos(handle); bool readres = IOUtil.Win32.Raw.ReadFile(_handle, _alignedBuffer[_bufferFillIndex], (int)Math.Min(_blockSize, _alignedLimit - _totalRead), out readBytes); - //t = DateTimeOffset.Now.UtcDateTime.Ticks - t; + //t = DateTime.UtcNow.Ticks - t; //Console.WriteLine("core time: " + (t / (double)TimeSpan.TicksPerSecond).ToString("0.000")); if (!readres) { diff --git a/src/Microsoft.ML.Maml/MAML.cs b/src/Microsoft.ML.Maml/MAML.cs index 24c52b6b88..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", DateTimeOffset.Now.UtcDateTime, 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 40bc45a691..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 = DateTimeOffset.Now.UtcDateTime.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 9cee00210b..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", DateTimeOffset.Now.UtcDateTime, 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}", DateTimeOffset.Now.UtcDateTime, 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, DateTimeOffset.Now.UtcDateTime); + 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.", - DateTimeOffset.Now.UtcDateTime, 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(DateTimeOffset.Now.UtcDateTime); + Host.StdOut.Write(DateTime.UtcNow); } Host.StdOut.WriteLine(); } From b6c5d50776cc80f62e3fde794d0ef767a679cad7 Mon Sep 17 00:00:00 2001 From: Sorrien Date: Fri, 11 May 2018 18:31:27 -0400 Subject: [PATCH 5/6] Replaced starttime measurement with stopwatch and reverted change that removed timezone info where it was actually needed --- src/Microsoft.ML.Core/Data/DateTime.cs | 2 +- .../EnsembleCompression/LassoBasedEnsembleCompressor.cs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.ML.Core/Data/DateTime.cs b/src/Microsoft.ML.Core/Data/DateTime.cs index d4840f89bd..52b30b5bb6 100644 --- a/src/Microsoft.ML.Core/Data/DateTime.cs +++ b/src/Microsoft.ML.Core/Data/DateTime.cs @@ -201,7 +201,7 @@ public DvDateTimeZone(SysDateTimeOffset dto) // Since it is constructed from a SysDateTimeOffset, all the validations should work. var success = TryValidateOffset(dto.Offset.Ticks, out _offset); Contracts.Assert(success); - _dateTime = ValidateDate(new DvDateTime(dto.UtcDateTime), ref _offset); + _dateTime = ValidateDate(new DvDateTime(dto.DateTime), ref _offset); Contracts.Assert(!_dateTime.IsNA); Contracts.Assert(!_offset.IsNA); AssertValid(); diff --git a/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs b/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs index 3a32cf033d..2015e7d246 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,8 @@ public unsafe void SetTreeScores(int idx, double[] scores) private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel) { - DateTime startTime = DateTime.UtcNow; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); if (maxAllowedFeaturesPerModel < 0) { @@ -450,8 +452,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.UtcNow - startTime; - ch.Info("Elapsed time for compression: {0}", duration); + stopWatch.Stop(); + ch.Info("Elapsed time for compression: {0}", stopWatch.Elapsed); return fit; } From 4266612119caae5a449a58180c918fd0027c37c5 Mon Sep 17 00:00:00 2001 From: Sorrien Date: Fri, 11 May 2018 20:00:18 -0400 Subject: [PATCH 6/6] opted for the one liner version instantiating and starting the stopwatch --- .../EnsembleCompression/LassoBasedEnsembleCompressor.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs b/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs index 2015e7d246..5758e619cb 100644 --- a/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs +++ b/src/Microsoft.ML.FastTree/Training/EnsembleCompression/LassoBasedEnsembleCompressor.cs @@ -165,8 +165,7 @@ public unsafe void SetTreeScores(int idx, double[] scores) private LassoFit GetLassoFit(IChannel ch, int maxAllowedFeaturesPerModel) { - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); + Stopwatch stopWatch = Stopwatch.StartNew(); if (maxAllowedFeaturesPerModel < 0) {