Last active
          August 26, 2025 00:33 
        
      - 
      
 - 
        
Save xtqqczze/5209e139d4bea52188a6a27b34212def to your computer and use it in GitHub Desktop.  
  
    
      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 System; | |
| using System.Collections; | |
| using System.Linq; | |
| using BenchmarkDotNet.Attributes; | |
| [MemoryDiagnoser] | |
| public class Benchmarks | |
| { | |
| private readonly IDictionary _dict = Enumerable.Range(0, 10000).ToDictionary(i => i.ToString(), i => string.Empty); | |
| [Benchmark] | |
| public void DictionaryEntry() | |
| { | |
| foreach (DictionaryEntry entry in _dict) | |
| { | |
| _ = (string)entry.Value; | |
| } | |
| } | |
| [Benchmark] | |
| public void IDictionaryEnumerator() | |
| { | |
| IDictionaryEnumerator e = _dict.GetEnumerator(); | |
| try | |
| { | |
| while (e.MoveNext()) | |
| { | |
| DictionaryEntry entry = e.Entry; | |
| _ = (string)entry.Value; | |
| } | |
| } | |
| finally | |
| { | |
| (e as IDisposable)?.Dispose(); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment