You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2020/02/09 06:16:08 UTC

[lucenenet] 16/35: BREAKING: Lucene.Net.Support: Marked Time class internal, factored out CurrentTimeMilliseconds() in favor of J2N's

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 3fe42031d2c25996f0ce4bf24688217a94bdaa41
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Fri Feb 7 00:01:14 2020 +0700

    BREAKING: Lucene.Net.Support: Marked Time class internal, factored out CurrentTimeMilliseconds() in favor of J2N's
---
 src/Lucene.Net.Benchmark/ByTask/PerfRunData.cs     |  2 +-
 src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs |  2 +-
 .../ByTask/Tasks/NearRealtimeReaderTask.cs         |  8 ++---
 .../ByTask/Tasks/TaskSequence.cs                   | 18 +++++-----
 .../Quality/QualityBenchmark.cs                    | 10 +++---
 src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs |  4 +--
 .../ByTask/Feeds/DocMakerTest.cs                   |  2 +-
 .../ByTask/Tasks/CountingSearchTestTask.cs         |  2 +-
 src/Lucene.Net/Support/Time.cs                     | 38 +++++++++-------------
 src/Lucene.Net/Util/StringHelper.cs                |  2 +-
 10 files changed, 41 insertions(+), 47 deletions(-)

diff --git a/src/Lucene.Net.Benchmark/ByTask/PerfRunData.cs b/src/Lucene.Net.Benchmark/ByTask/PerfRunData.cs
index 136f968..a0c5bc4 100644
--- a/src/Lucene.Net.Benchmark/ByTask/PerfRunData.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/PerfRunData.cs
@@ -227,7 +227,7 @@ namespace Lucene.Net.Benchmarks.ByTask
 
         public virtual long SetStartTimeMillis()
         {
-            startTimeMillis = Support.Time.CurrentTimeMilliseconds();
+            startTimeMillis = J2N.Time.CurrentTimeMilliseconds();
             return startTimeMillis;
         }
 
diff --git a/src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs b/src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs
index 94d354b..00be92a 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Stats/TaskStats.cs
@@ -91,7 +91,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Stats
         /// </summary>
         internal void MarkEnd(int numParallelTasks, int count)
         {
-            elapsed = Support.Time.CurrentTimeMilliseconds();
+            elapsed = J2N.Time.CurrentTimeMilliseconds();
             long totMem = GC.GetTotalMemory(false); //Runtime.getRuntime().totalMemory();
             if (totMem > maxTotMem)
             {
diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/NearRealtimeReaderTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/NearRealtimeReaderTask.cs
index 7942156..1e3dd08 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Tasks/NearRealtimeReaderTask.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/NearRealtimeReaderTask.cs
@@ -63,7 +63,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
             }
 
 
-            long t = Support.Time.CurrentTimeMilliseconds();
+            long t = J2N.Time.CurrentTimeMilliseconds();
             DirectoryReader r = DirectoryReader.Open(w, true);
             runData.SetIndexReader(r);
             // Transfer our reference to runData
@@ -76,18 +76,18 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
             reopenCount = 0;
             while (!Stop)
             {
-                long waitForMsec = (pauseMSec - (Support.Time.CurrentTimeMilliseconds() - t));
+                long waitForMsec = (pauseMSec - (J2N.Time.CurrentTimeMilliseconds() - t));
                 if (waitForMsec > 0)
                 {
                     Thread.Sleep((int)waitForMsec);
                     //System.out.println("NRT wait: " + waitForMsec + " msec");
                 }
 
-                t = Support.Time.CurrentTimeMilliseconds();
+                t = J2N.Time.CurrentTimeMilliseconds();
                 DirectoryReader newReader = DirectoryReader.OpenIfChanged(r);
                 if (newReader != null)
                 {
-                    int delay = (int)(Support.Time.CurrentTimeMilliseconds() - t);
+                    int delay = (int)(J2N.Time.CurrentTimeMilliseconds() - t);
                     if (reopenTimes.Length == reopenCount)
                     {
                         reopenTimes = ArrayUtil.Grow(reopenTimes, 1 + reopenCount);
diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs
index 66fb220..348a7e7 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/TaskSequence.cs
@@ -201,7 +201,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
             long runTime = (long)(runTimeSec * 1000);
             List<RunBackgroundTask> bgTasks = null;
 
-            long t0 = Support.Time.CurrentTimeMilliseconds();
+            long t0 = J2N.Time.CurrentTimeMilliseconds();
             for (int k = 0; fixedTime || (repetitions == REPEAT_EXHAUST && !exhausted) || k < repetitions; k++)
             {
                 if (Stop)
@@ -232,7 +232,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
                             count += inc;
                             if (countsByTime != null)
                             {
-                                int slot = (int)((Support.Time.CurrentTimeMilliseconds() - t0) / logByTimeMsec);
+                                int slot = (int)((J2N.Time.CurrentTimeMilliseconds() - t0) / logByTimeMsec);
                                 if (slot >= countsByTime.Length)
                                 {
                                     countsByTime = ArrayUtil.Grow(countsByTime, 1 + slot);
@@ -248,7 +248,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
                         }
                     }
                 }
-                if (fixedTime && Support.Time.CurrentTimeMilliseconds() - t0 > runTime)
+                if (fixedTime && J2N.Time.CurrentTimeMilliseconds() - t0 > runTime)
                 {
                     repetitions = k + 1;
                     break;
@@ -282,9 +282,9 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
         {
             InitTasksArray();
             long delayStep = (perMin ? 60000 : 1000) / rate;
-            long nextStartTime = Support.Time.CurrentTimeMilliseconds();
+            long nextStartTime = J2N.Time.CurrentTimeMilliseconds();
             int count = 0;
-            long t0 = Support.Time.CurrentTimeMilliseconds();
+            long t0 = J2N.Time.CurrentTimeMilliseconds();
             for (int k = 0; (repetitions == REPEAT_EXHAUST && !exhausted) || k < repetitions; k++)
             {
                 if (Stop)
@@ -296,7 +296,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
                     PerfTask task = tasksArray[l];
                     while (!Stop)
                     {
-                        long waitMore = nextStartTime - Support.Time.CurrentTimeMilliseconds();
+                        long waitMore = nextStartTime - J2N.Time.CurrentTimeMilliseconds();
                         if (waitMore > 0)
                         {
                             // TODO: better to use condition to notify
@@ -318,7 +318,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
                         count += inc;
                         if (countsByTime != null)
                         {
-                            int slot = (int)((Support.Time.CurrentTimeMilliseconds() - t0) / logByTimeMsec);
+                            int slot = (int)((J2N.Time.CurrentTimeMilliseconds() - t0) / logByTimeMsec);
                             if (slot >= countsByTime.Length)
                             {
                                 countsByTime = ArrayUtil.Grow(countsByTime, 1 + slot);
@@ -509,10 +509,10 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
         private void StartlThreadsWithRate(ParallelTask[] t)
         {
             long delayStep = (perMin ? 60000 : 1000) / rate;
-            long nextStartTime = Support.Time.CurrentTimeMilliseconds();
+            long nextStartTime = J2N.Time.CurrentTimeMilliseconds();
             for (int i = 0; i < t.Length; i++)
             {
-                long waitMore = nextStartTime - Support.Time.CurrentTimeMilliseconds();
+                long waitMore = nextStartTime - J2N.Time.CurrentTimeMilliseconds();
                 if (waitMore > 0)
                 {
                     Thread.Sleep((int)waitMore);
diff --git a/src/Lucene.Net.Benchmark/Quality/QualityBenchmark.cs b/src/Lucene.Net.Benchmark/Quality/QualityBenchmark.cs
index ef53e25..aac26c4 100644
--- a/src/Lucene.Net.Benchmark/Quality/QualityBenchmark.cs
+++ b/src/Lucene.Net.Benchmark/Quality/QualityBenchmark.cs
@@ -95,9 +95,9 @@ namespace Lucene.Net.Benchmarks.Quality
                 // generate query
                 Query q = m_qqParser.Parse(qq);
                 // search with this query 
-                long t1 = Support.Time.CurrentTimeMilliseconds();
+                long t1 = J2N.Time.CurrentTimeMilliseconds();
                 TopDocs td = m_searcher.Search(q, null, maxResults);
-                long searchTime = Support.Time.CurrentTimeMilliseconds() - t1;
+                long searchTime = J2N.Time.CurrentTimeMilliseconds() - t1;
                 //most likely we either submit or judge, but check both 
                 if (judge != null)
                 {
@@ -120,13 +120,13 @@ namespace Lucene.Net.Benchmarks.Quality
         {
             QualityStats stts = new QualityStats(judge.MaxRecall(qq), searchTime);
             ScoreDoc[] sd = td.ScoreDocs;
-            long t1 = Support.Time.CurrentTimeMilliseconds(); // extraction of first doc name we measure also construction of doc name extractor, just in case.
+            long t1 = J2N.Time.CurrentTimeMilliseconds(); // extraction of first doc name we measure also construction of doc name extractor, just in case.
             DocNameExtractor xt = new DocNameExtractor(m_docNameField);
             for (int i = 0; i < sd.Length; i++)
             {
                 string docName = xt.DocName(m_searcher, sd[i].Doc);
-                long docNameExtractTime = Support.Time.CurrentTimeMilliseconds() - t1;
-                t1 = Support.Time.CurrentTimeMilliseconds();
+                long docNameExtractTime = J2N.Time.CurrentTimeMilliseconds() - t1;
+                t1 = J2N.Time.CurrentTimeMilliseconds();
                 bool isRelevant = judge.IsRelevant(docName, qq);
                 stts.AddResult(i + 1, isRelevant, docNameExtractTime);
             }
diff --git a/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs b/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs
index b322996..775d14f 100644
--- a/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs
+++ b/src/Lucene.Net.Benchmark/Utils/ExtractWikipedia.cs
@@ -101,7 +101,7 @@ namespace Lucene.Net.Benchmarks.Utils
         {
             Document doc = null;
             Console.WriteLine("Starting Extraction");
-            long start = Support.Time.CurrentTimeMilliseconds();
+            long start = J2N.Time.CurrentTimeMilliseconds();
             try
             {
                 while ((doc = m_docMaker.MakeDocument()) != null)
@@ -114,7 +114,7 @@ namespace Lucene.Net.Benchmarks.Utils
             {
                 //continue
             }
-            long finish = Support.Time.CurrentTimeMilliseconds();
+            long finish = J2N.Time.CurrentTimeMilliseconds();
             Console.WriteLine("Extraction took " + (finish - start) + " ms");
         }
 
diff --git a/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/DocMakerTest.cs b/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/DocMakerTest.cs
index c19c774..b10b08a 100644
--- a/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/DocMakerTest.cs
+++ b/src/Lucene.Net.Tests.Benchmark/ByTask/Feeds/DocMakerTest.cs
@@ -171,7 +171,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds
             // leading to a file handle leak.
             FileInfo f = new FileInfo(Path.Combine(getWorkDir().FullName, "docMakerLeak.txt"));
             TextWriter ps = new StreamWriter(new FileStream(f.FullName, FileMode.Create, FileAccess.Write), Encoding.UTF8);
-            ps.WriteLine("one title\t" + Time.CurrentTimeMilliseconds() + "\tsome content");
+            ps.WriteLine("one title\t" + J2N.Time.CurrentTimeMilliseconds() + "\tsome content");
             ps.Dispose();
 
             Dictionary<string, string> props = new Dictionary<string, string>();
diff --git a/src/Lucene.Net.Tests.Benchmark/ByTask/Tasks/CountingSearchTestTask.cs b/src/Lucene.Net.Tests.Benchmark/ByTask/Tasks/CountingSearchTestTask.cs
index 10c7628..87d56ea 100644
--- a/src/Lucene.Net.Tests.Benchmark/ByTask/Tasks/CountingSearchTestTask.cs
+++ b/src/Lucene.Net.Tests.Benchmark/ByTask/Tasks/CountingSearchTestTask.cs
@@ -48,7 +48,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
             lock (syncLock)
             {
                 prevLastMillis = lastMillis;
-                lastMillis = Time.CurrentTimeMilliseconds();
+                lastMillis = J2N.Time.CurrentTimeMilliseconds();
                 if (0 == numSearches)
                 {
                     startMillis = prevLastMillis = lastMillis;
diff --git a/src/Lucene.Net/Support/Time.cs b/src/Lucene.Net/Support/Time.cs
index cec17e8..91d5657 100644
--- a/src/Lucene.Net/Support/Time.cs
+++ b/src/Lucene.Net/Support/Time.cs
@@ -1,26 +1,25 @@
 using System;
-using System.Diagnostics;
 
 namespace Lucene.Net.Support
 {
     /*
-	 * Licensed to the Apache Software Foundation (ASF) under one or more
-	 * contributor license agreements.  See the NOTICE file distributed with
-	 * this work for additional information regarding copyright ownership.
-	 * The ASF licenses this file to You under the Apache License, Version 2.0
-	 * (the "License"); you may not use this file except in compliance with
-	 * the License.  You may obtain a copy of the License at
-	 *
-	 *     http://www.apache.org/licenses/LICENSE-2.0
-	 *
-	 * Unless required by applicable law or agreed to in writing, software
-	 * distributed under the License is distributed on an "AS IS" BASIS,
-	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-	 * See the License for the specific language governing permissions and
-	 * limitations under the License.
-	 */
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
 
-    public static class Time
+    internal static class Time
     {
         public const long MILLISECONDS_PER_NANOSECOND = 1000000;
         public const long TICKS_PER_NANOSECOND = 100;
@@ -32,10 +31,5 @@ namespace Lucene.Net.Support
             // return (Stopwatch.GetTimestamp() / Stopwatch.Frequency) * 1000000000;
             // for better accuracy that is not affected by the system clock
         }
-
-        public static long CurrentTimeMilliseconds()
-        {
-            return (Stopwatch.GetTimestamp() / Stopwatch.Frequency) * 1000;
-        }
     }
 }
\ No newline at end of file
diff --git a/src/Lucene.Net/Util/StringHelper.cs b/src/Lucene.Net/Util/StringHelper.cs
index 5fbfb4e..b85ed37 100644
--- a/src/Lucene.Net/Util/StringHelper.cs
+++ b/src/Lucene.Net/Util/StringHelper.cs
@@ -58,7 +58,7 @@ namespace Lucene.Net.Util
             }
             else
             {
-                return (int)Time.CurrentTimeMilliseconds();
+                return (int)J2N.Time.CurrentTimeMilliseconds();
             }
         }