lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucenenet] theolivenbaum commented on issue #346: Remove Debugging.AssertsEnabled
Date Wed, 23 Sep 2020 09:48:18 GMT

theolivenbaum commented on issue #346:
URL: https://github.com/apache/lucenenet/issues/346#issuecomment-697257440


   
   Tried on a very simple benchmark - running on a laptop so don't expect perfect results...
In any case I think the gain is obviouos :)
   
   ```csharp
       [SimpleJob(RuntimeMoniker.NetCoreApp31)]
       public class DebuggingFlags
       {
           private static Dictionary<string, string> _flags = new Dictionary<string,
string>() { ["assert"] = "false" };
   
           private HashSet<int> _set = new HashSet<int>();
   
           [Params(1000, 10000, 100_000)]
           public int N;
   
           [Benchmark]
           public void Loop()
           {
               for (int i = 0; i < N; i++)
               {
                   Set(i);
               }
           }
   
           [Benchmark]
           public void CachedLoop()
           {
               bool flag = AssertsEnabled;
               for (int i = 0; i < N; i++)
               {
                   SetPassingFlag(i, flag);
               }
           }
   
           internal static bool AssertsEnabled
           {
               get
               {
                   return _flags.TryGetValue("assert", out var flag) ? bool.Parse(flag) :
false;
               }
           }
   
           private void Set(int index)
           {
               SetPassingFlag(index, AssertsEnabled);
           }
   
           private void SetPassingFlag(int index, bool flag)
           {
               if (flag) Assert(index > 0 && index < N);
   
               _set.Add(index);
           }
   
           private static void Assert(bool condition)
           {
               if (condition) throw new Exception("Failed assertion");
           }
       }
   ```
   
   |     Method |           Job |       Runtime |      N |         Mean |       Error |  
   StdDev | Ratio | RatioSD |
   |----------- |-------------- |-------------- |------- |-------------:|------------:|------------:|------:|--------:|
   |       Loop | .NET Core 3.1 | .NET Core 3.1 |   1000 |    55.457 us |   0.7818 us |  
0.6528 us |     ? |       ? |
   | CachedLoop | .NET Core 3.1 | .NET Core 3.1 |   1000 |     8.953 us |   0.1000 us |  
0.0835 us |     ? |       ? |
   |       Loop | .NET Core 3.1 | .NET Core 3.1 |  10000 |   556.303 us |   7.2915 us |  
6.0887 us |     ? |       ? |
   | CachedLoop | .NET Core 3.1 | .NET Core 3.1 |  10000 |    89.656 us |   1.1263 us |  
1.8819 us |     ? |       ? |
   |       Loop | .NET Core 3.1 | .NET Core 3.1 | 100000 | 6,341.585 us | 207.3166 us | 581.3379
us |     ? |       ? |
   | CachedLoop | .NET Core 3.1 | .NET Core 3.1 | 100000 | 1,029.926 us |  28.9745 us |  81.7231
us |     ? |       ? |
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message