File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ using System . Collections . Concurrent ;
2+ using System . Threading . Tasks ;
3+ using BenchmarkDotNet . Attributes ;
4+ using BenchmarkDotNet . Columns ;
5+ using BenchmarkDotNet . Configs ;
6+ using BenchmarkDotNet . Diagnosers ;
7+ using BenchmarkDotNet . Exporters ;
8+ using BenchmarkDotNet . Jobs ;
9+
10+ namespace MicroBenchmarks . Linq
11+ {
12+ [ Config ( typeof ( Config ) ) ]
13+ public class ConcurrentQueueVsConcurrentBag_Adding
14+ {
15+ private ConcurrentQueue < int > queue ;
16+ private ConcurrentBag < int > bag ;
17+
18+ private class Config : ManualConfig
19+ {
20+ public Config ( )
21+ {
22+ Add ( MarkdownExporter . GitHub ) ;
23+ Add ( MemoryDiagnoser . Default ) ;
24+ Add ( StatisticColumn . AllStatistics ) ;
25+ Add ( Job . MediumRun ) ;
26+ }
27+ }
28+
29+ [ GlobalSetup ]
30+ public void SetUp ( )
31+ {
32+ queue = new ConcurrentQueue < int > ( ) ;
33+ bag = new ConcurrentBag < int > ( ) ;
34+ }
35+
36+ [ Benchmark ( Baseline = true ) ]
37+ public void ConcurrentQueue_Enqueue ( )
38+ {
39+ Parallel . For ( 0 , 1000 , i => queue . Enqueue ( i ) ) ;
40+ }
41+
42+ [ Benchmark ]
43+ public void ConcurrentBag_Add ( )
44+ {
45+ Parallel . For ( 0 , 1000 , i => bag . Add ( i ) ) ;
46+ }
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments