Created
          January 22, 2021 23:25 
        
      - 
      
 - 
        
Save xtqqczze/6c282c3519258c2ad250c861a37f2353 to your computer and use it in GitHub Desktop.  
    BenchmarkStringContains
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using BenchmarkDotNet.Attributes; | |
| using BenchmarkDotNet.Running; | |
| using System; | |
| [MemoryDiagnoser] | |
| [DisassemblyDiagnoser] | |
| public class Program | |
| { | |
| private string str = "whatever"; | |
| private string find = "a"; | |
| private char findChar = 'a'; | |
| static void Main() | |
| { | |
| BenchmarkRunner.Run<Program>(); | |
| } | |
| [Benchmark] | |
| public bool ContainsStringLocal() | |
| { | |
| string temp = "a"; | |
| return str.Contains(temp); | |
| } | |
| [Benchmark] | |
| public bool ContainsStringField() | |
| { | |
| return str.Contains(find); | |
| } | |
| [Benchmark] | |
| public bool ContainsCharLocal() | |
| { | |
| char temp = 'a'; | |
| return str.Contains(temp); | |
| } | |
| [Benchmark] | |
| public bool ContainsCharField() | |
| { | |
| return str.Contains(findChar); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment