lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucenenet] jeme edited a comment on pull request #345: Reduce casting
Date Tue, 22 Sep 2020 17:54:44 GMT

jeme edited a comment on pull request #345:
URL: https://github.com/apache/lucenenet/pull/345#issuecomment-696880214


   Been trying to put some benchmarks together, can't quite get the Allocations into the report,
but so far there seems to be no reasons to avoid pattern matching...
   
   Also, this doesn't quite hit all the cases (e.g. where there are null checks before the
conversions etc.) so will work a bit further to see if I can get that in and have the report
still be digestable.
   
   ``` 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.301
     [Host]        : .NET Core 3.1.5 (CoreCLR 4.700.20.26901, CoreFX 4.700.20.27001), X64
RyuJIT
     .NET 4.8      : .NET Framework 4.8 (4.8.4220.0), X64 RyuJIT
     .NET Core 3.1 : .NET Core 3.1.5 (CoreCLR 4.700.20.26901, CoreFX 4.700.20.27001), X64
RyuJIT
   
   
   ```
   |                         Method |           Job |       Runtime |     Mean |     Error
|    StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
   |------------------------------- |-------------- |-------------- |---------:|----------:|----------:|------:|------:|------:|----------:|
   |    AsOperatorNullCheckMatching |      .NET 4.8 |      .NET 4.8 | 1.748 ns | 0.0368 ns
| 0.0344 ns |     - |     - |     - |         - |
   | AsOperatorNullCheckNonMatching |      .NET 4.8 |      .NET 4.8 | 2.094 ns | 0.0708 ns
| 0.0757 ns |     - |     - |     - |         - |
   |              IsPatternMatching |      .NET 4.8 |      .NET 4.8 | 1.812 ns | 0.0577 ns
| 0.0539 ns |     - |     - |     - |         - |
   |           IsPatternNonMatching |      .NET 4.8 |      .NET 4.8 | 2.105 ns | 0.0321 ns
| 0.0284 ns |     - |     - |     - |         - |
   |             IsThenCastMatching |      .NET 4.8 |      .NET 4.8 | 2.117 ns | 0.0706 ns
| 0.0660 ns |     - |     - |     - |         - |
   |          IsThenCastNonMatching |      .NET 4.8 |      .NET 4.8 | 2.512 ns | 0.0760 ns
| 0.0781 ns |     - |     - |     - |         - |
   |    AsOperatorNullCheckMatching | .NET Core 3.1 | .NET Core 3.1 | 1.478 ns | 0.0297 ns
| 0.0263 ns |     - |     - |     - |         - |
   | AsOperatorNullCheckNonMatching | .NET Core 3.1 | .NET Core 3.1 | 1.843 ns | 0.0431 ns
| 0.0382 ns |     - |     - |     - |         - |
   |              IsPatternMatching | .NET Core 3.1 | .NET Core 3.1 | 1.543 ns | 0.0448 ns
| 0.0419 ns |     - |     - |     - |         - |
   |           IsPatternNonMatching | .NET Core 3.1 | .NET Core 3.1 | 1.890 ns | 0.0531 ns
| 0.0443 ns |     - |     - |     - |         - |
   |             IsThenCastMatching | .NET Core 3.1 | .NET Core 3.1 | 1.898 ns | 0.0603 ns
| 0.0884 ns |     - |     - |     - |         - |
   |          IsThenCastNonMatching | .NET Core 3.1 | .NET Core 3.1 | 2.294 ns | 0.0525 ns
| 0.0438 ns |     - |     - |     - |         - |
   
   ----
   
   ```
       [MemoryDiagnoser]
       [SimpleJob(RuntimeMoniker.Net48)]
       [SimpleJob(RuntimeMoniker.NetCoreApp31)]
       public class PatternMatching
       {
           private object item = new ArrayList();
           private object nullitem = null;
   
           [Benchmark]
           public int AsOperatorNullCheckMatching()
           {
               var array = item as ArrayList;
               if (array != null) return array.Count;
               return 0;
           }
   
           [Benchmark]
           public int AsOperatorNullCheckNonMatching()
           {
               var table = item as Hashtable;
               if (table != null) return table.Count;
               return 0;
           }
   
           [Benchmark]
           public int IsPatternMatching()
           {
               if (item 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 IsThenCastMatching()
           {
               if (item is ArrayList) return ((ArrayList)item).Count;
               return 0;
           }
   
           [Benchmark]
           public int IsThenCastNonMatching()
           {
               if (item is Hashtable) return ((Hashtable)item as Hashtable).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