lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucenenet] jeme commented on pull request #345: Reduce casting
Date Tue, 22 Sep 2020 18:21:53 GMT

jeme commented on pull request #345:
URL: https://github.com/apache/lucenenet/pull/345#issuecomment-696897183


   Adding a null check before the pattern matching takes place:
   
   ----
   
   ``` ini
   
   BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18362.1082 (1903/May2019Update/19H1)
   Intel Core i9-7900X CPU 3.30GHz (Kaby Lake), 1 CPU, 20 logical and 10 physical cores
   .NET Core SDK=3.1.402
     [Host]        : .NET Core 3.1.8 (CoreCLR 4.700.20.41105, CoreFX 4.700.20.41903), X64
RyuJIT
     .NET 4.8      : .NET Framework 4.8 (4.8.4220.0), X64 RyuJIT
     .NET Core 3.1 : .NET Core 3.1.8 (CoreCLR 4.700.20.41105, CoreFX 4.700.20.41903), X64
RyuJIT
   
   
   ```
   |                      Method |           Job |       Runtime |      Mean |     Error |
   StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
   |---------------------------- |-------------- |-------------- |----------:|----------:|----------:|------:|------:|------:|----------:|
   |           IsPatternMatching |      .NET 4.8 |      .NET 4.8 | 1.8286 ns | 0.0508 ns |
0.0451 ns |     - |     - |     - |         - |
   |    NotNullIsPatternMatching |      .NET 4.8 |      .NET 4.8 | 1.7808 ns | 0.0520 ns |
0.0486 ns |     - |     - |     - |         - |
   |       NullIsPatternMatching |      .NET 4.8 |      .NET 4.8 | 0.2407 ns | 0.0251 ns |
0.0235 ns |     - |     - |     - |         - |
   |        IsPatternNonMatching |      .NET 4.8 |      .NET 4.8 | 2.0952 ns | 0.0367 ns |
0.0306 ns |     - |     - |     - |         - |
   | NotNullIsPatternNonMatching |      .NET 4.8 |      .NET 4.8 | 2.1074 ns | 0.0341 ns |
0.0302 ns |     - |     - |     - |         - |
   |    NullIsPatternNonMatching |      .NET 4.8 |      .NET 4.8 | 0.2694 ns | 0.0063 ns |
0.0056 ns |     - |     - |     - |         - |
   |           IsPatternMatching | .NET Core 3.1 | .NET Core 3.1 | 1.3430 ns | 0.0292 ns |
0.0273 ns |     - |     - |     - |         - |
   |    NotNullIsPatternMatching | .NET Core 3.1 | .NET Core 3.1 | 1.5368 ns | 0.0275 ns |
0.0257 ns |     - |     - |     - |         - |
   |       NullIsPatternMatching | .NET Core 3.1 | .NET Core 3.1 | 0.2990 ns | 0.0214 ns |
0.0190 ns |     - |     - |     - |         - |
   |        IsPatternNonMatching | .NET Core 3.1 | .NET Core 3.1 | 1.9393 ns | 0.0542 ns |
0.0507 ns |     - |     - |     - |         - |
   | NotNullIsPatternNonMatching | .NET Core 3.1 | .NET Core 3.1 | 1.8874 ns | 0.0295 ns |
0.0261 ns |     - |     - |     - |         - |
   |    NullIsPatternNonMatching | .NET Core 3.1 | .NET Core 3.1 | 0.2634 ns | 0.0258 ns |
0.0242 ns |     - |     - |     - |         - |
   
   ----
   
   ```csharp
           [Benchmark]
           public int IsPatternMatching()
           {
               if (item is ArrayList table) return table.Count;
               return 0;
           }
   
           [Benchmark]
           public int NotNullIsPatternMatching()
           {
               if (item != null && item is ArrayList table) return table.Count;
               return 0;
           }
   
           [Benchmark]
           public int NullIsPatternMatching()
           {
               if (nullitem != null && nullitem is ArrayList table) return table.Count;
               return 0;
           }
   
   
           [Benchmark]
           public int IsPatternNonMatching()
           {
               if (item is Hashtable table) return table.Count;
               return 0;
           }
   
           [Benchmark]
           public int NotNullIsPatternNonMatching()
           {
               if (item != null && item is Hashtable table) return table.Count;
               return 0;
           }
   
           [Benchmark]
           public int NullIsPatternNonMatching()
           {
               if (nullitem != null && nullitem is Hashtable table) return table.Count;
               return 0;
           }
   ```


----------------------------------------------------------------
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