44using BenchmarkDotNet . Engines ;
55using JsonFlatFileDataStore . Test ;
66
7- namespace JsonFlatFileDataStore . Benchmark
7+ namespace JsonFlatFileDataStore . Benchmark ;
8+
9+ [ SimpleJob ( RunStrategy . Monitoring , launchCount : 1 , warmupCount : 5 , iterationCount : 50 ) ]
10+ public class DynamicCollectionBenchmark
811{
9- [ SimpleJob ( RunStrategy . Monitoring , launchCount : 1 , warmupCount : 5 , iterationCount : 50 ) ]
10- public class DynamicCollectionBenchmark
11- {
12- private string _newFilePath ;
13- private IDataStore _store ;
14- private IDocumentCollection < dynamic > _collection ;
15-
16- [ GlobalSetup ]
17- public void GlobalSetup ( )
18- {
19- _newFilePath = UTHelpers . Up ( ) ;
20- _store = new DataStore ( _newFilePath ) ;
21- _collection = _store . GetCollection ( "user" ) ;
22- }
23-
24- [ GlobalCleanup ]
25- public void GlobalCleanup ( ) => UTHelpers . Down ( _newFilePath ) ;
26-
27- [ Benchmark ]
28- public void AsQueryable_Single ( )
29- {
30- var item = _collection . AsQueryable ( ) . Single ( e => e . id == 1 ) ;
31- }
32-
33- [ Benchmark ]
34- public async Task InsertOneAsync ( )
35- {
36- await _collection . InsertOneAsync ( new { name = "Teddy" } ) ;
37- }
38-
39- [ Benchmark ]
40- public void InsertOne ( )
41- {
42- _collection . InsertOne ( new { name = "Teddy" } ) ;
43- }
44-
45- [ Benchmark ]
46- public async Task InsertManyAsync ( )
47- {
48- var items = Enumerable . Range ( 0 , 100 ) . Select ( e => new { id = e , name = $ "Teddy_{ e } " } ) ;
49- await _collection . InsertManyAsync ( items ) ;
50- }
51-
52- [ Benchmark ]
53- public void InsertMany ( )
54- {
55- var items = Enumerable . Range ( 0 , 100 ) . Select ( e => new { id = e , name = $ "Teddy_{ e } " } ) ;
56- _collection . InsertMany ( items ) ;
57- }
58-
59- [ Benchmark ]
60- public async Task DeleteOneAsync_With_Id ( )
61- {
62- await _collection . DeleteOneAsync ( 1 ) ;
63- }
64-
65- [ Benchmark ]
66- public async Task DeleteOneAsync_With_Predicate ( )
67- {
68- await _collection . DeleteOneAsync ( e => e . id == 1 ) ;
69- }
70-
71- [ Benchmark ]
72- public void DeleteMany ( )
73- {
74- _collection . DeleteMany ( e => true ) ;
75- }
76-
77- [ Benchmark ]
78- public async Task DeleteManyAsync ( )
79- {
80- await _collection . DeleteManyAsync ( e => true ) ;
81- }
82-
83- [ Benchmark ]
84- public void ReplaceOne_With_Predicate ( )
85- {
86- _collection . ReplaceOne ( e => e . id == 1 , new { id = 1 , name = "Teddy" } ) ;
87- }
88-
89- [ Benchmark ]
90- public void ReplaceOne_With_Id ( )
91- {
92- _collection . ReplaceOne ( 1 , new { id = 1 , name = "Teddy" } ) ;
93- }
94-
95- [ Benchmark ]
96- public async Task ReplaceOneAsync_With_Predicate ( )
97- {
98- await _collection . ReplaceOneAsync ( e => e . id == 1 , new { id = 1 , name = "Teddy" } ) ;
99- }
100-
101- [ Benchmark ]
102- public async Task ReplaceOneAsync_With_Id ( )
103- {
104- await _collection . ReplaceOneAsync ( 1 , new { id = 1 , name = "Teddy" } ) ;
105- }
106-
107- [ Benchmark ]
108- public void ReplaceMany ( )
109- {
110- _collection . ReplaceMany ( e => true , new { id = 1 , name = "Teddy" } ) ;
111- }
112-
113- [ Benchmark ]
114- public async Task ReplaceManyAsync ( )
115- {
116- await _collection . ReplaceManyAsync ( e => true , new { id = 1 , name = "Teddy" } ) ;
117- }
118-
119- [ Benchmark ]
120- public void UpdateOne ( )
121- {
122- _collection . UpdateOne ( e => e . id == 1 , new { name = "Teddy" } ) ;
123- }
124-
125- [ Benchmark ]
126- public async Task UpdateOneAsync ( )
127- {
128- await _collection . UpdateOneAsync ( e => e . id == 1 , new { name = "Teddy" } ) ;
129- }
130-
131- [ Benchmark ]
132- public void UpdateMany ( )
133- {
134- _collection . UpdateMany ( e => true , new { name = "Teddy" } ) ;
135- }
136-
137- [ Benchmark ]
138- public async Task UpdateManyAsync ( )
139- {
140- await _collection . UpdateManyAsync ( e => true , new { name = "Teddy" } ) ;
141- }
142-
143- [ Benchmark ]
144- public void Find_With_Predicate ( )
145- {
146- _collection . Find ( e => e . id == 1 ) ;
147- }
148-
149- [ Benchmark ]
150- public void Find_With_Text ( )
151- {
152- _collection . Find ( "James" ) ;
153- }
154-
155- [ Benchmark ]
156- public void GetNextIdValue ( )
157- {
158- _collection . GetNextIdValue ( ) ;
159- }
12+ private string _newFilePath ;
13+ private IDataStore _store ;
14+ private IDocumentCollection < dynamic > _collection ;
15+
16+ [ GlobalSetup ]
17+ public void GlobalSetup ( )
18+ {
19+ _newFilePath = UTHelpers . Up ( ) ;
20+ _store = new DataStore ( _newFilePath ) ;
21+ _collection = _store . GetCollection ( "user" ) ;
22+ }
23+
24+ [ GlobalCleanup ]
25+ public void GlobalCleanup ( ) => UTHelpers . Down ( _newFilePath ) ;
26+
27+ [ Benchmark ]
28+ public void AsQueryable_Single ( )
29+ {
30+ var item = _collection . AsQueryable ( ) . Single ( e => e . id == 1 ) ;
31+ }
32+
33+ [ Benchmark ]
34+ public async Task InsertOneAsync ( )
35+ {
36+ await _collection . InsertOneAsync ( new { name = "Teddy" } ) ;
37+ }
38+
39+ [ Benchmark ]
40+ public void InsertOne ( )
41+ {
42+ _collection . InsertOne ( new { name = "Teddy" } ) ;
43+ }
44+
45+ [ Benchmark ]
46+ public async Task InsertManyAsync ( )
47+ {
48+ var items = Enumerable . Range ( 0 , 100 ) . Select ( e => new { id = e , name = $ "Teddy_{ e } " } ) ;
49+ await _collection . InsertManyAsync ( items ) ;
50+ }
51+
52+ [ Benchmark ]
53+ public void InsertMany ( )
54+ {
55+ var items = Enumerable . Range ( 0 , 100 ) . Select ( e => new { id = e , name = $ "Teddy_{ e } " } ) ;
56+ _collection . InsertMany ( items ) ;
57+ }
58+
59+ [ Benchmark ]
60+ public async Task DeleteOneAsync_With_Id ( )
61+ {
62+ await _collection . DeleteOneAsync ( 1 ) ;
63+ }
64+
65+ [ Benchmark ]
66+ public async Task DeleteOneAsync_With_Predicate ( )
67+ {
68+ await _collection . DeleteOneAsync ( e => e . id == 1 ) ;
69+ }
70+
71+ [ Benchmark ]
72+ public void DeleteMany ( )
73+ {
74+ _collection . DeleteMany ( e => true ) ;
75+ }
76+
77+ [ Benchmark ]
78+ public async Task DeleteManyAsync ( )
79+ {
80+ await _collection . DeleteManyAsync ( e => true ) ;
81+ }
82+
83+ [ Benchmark ]
84+ public void ReplaceOne_With_Predicate ( )
85+ {
86+ _collection . ReplaceOne ( e => e . id == 1 , new { id = 1 , name = "Teddy" } ) ;
87+ }
88+
89+ [ Benchmark ]
90+ public void ReplaceOne_With_Id ( )
91+ {
92+ _collection . ReplaceOne ( 1 , new { id = 1 , name = "Teddy" } ) ;
93+ }
94+
95+ [ Benchmark ]
96+ public async Task ReplaceOneAsync_With_Predicate ( )
97+ {
98+ await _collection . ReplaceOneAsync ( e => e . id == 1 , new { id = 1 , name = "Teddy" } ) ;
99+ }
100+
101+ [ Benchmark ]
102+ public async Task ReplaceOneAsync_With_Id ( )
103+ {
104+ await _collection . ReplaceOneAsync ( 1 , new { id = 1 , name = "Teddy" } ) ;
105+ }
106+
107+ [ Benchmark ]
108+ public void ReplaceMany ( )
109+ {
110+ _collection . ReplaceMany ( e => true , new { id = 1 , name = "Teddy" } ) ;
111+ }
112+
113+ [ Benchmark ]
114+ public async Task ReplaceManyAsync ( )
115+ {
116+ await _collection . ReplaceManyAsync ( e => true , new { id = 1 , name = "Teddy" } ) ;
117+ }
118+
119+ [ Benchmark ]
120+ public void UpdateOne ( )
121+ {
122+ _collection . UpdateOne ( e => e . id == 1 , new { name = "Teddy" } ) ;
123+ }
124+
125+ [ Benchmark ]
126+ public async Task UpdateOneAsync ( )
127+ {
128+ await _collection . UpdateOneAsync ( e => e . id == 1 , new { name = "Teddy" } ) ;
129+ }
130+
131+ [ Benchmark ]
132+ public void UpdateMany ( )
133+ {
134+ _collection . UpdateMany ( e => true , new { name = "Teddy" } ) ;
135+ }
136+
137+ [ Benchmark ]
138+ public async Task UpdateManyAsync ( )
139+ {
140+ await _collection . UpdateManyAsync ( e => true , new { name = "Teddy" } ) ;
141+ }
142+
143+ [ Benchmark ]
144+ public void Find_With_Predicate ( )
145+ {
146+ _collection . Find ( e => e . id == 1 ) ;
147+ }
148+
149+ [ Benchmark ]
150+ public void Find_With_Text ( )
151+ {
152+ _collection . Find ( "James" ) ;
153+ }
154+
155+ [ Benchmark ]
156+ public void GetNextIdValue ( )
157+ {
158+ _collection . GetNextIdValue ( ) ;
160159 }
161160}
0 commit comments