2121using MongoDB . Bson ;
2222using MongoDB . Driver ;
2323
24- namespace MongoDB . Benchmarks
24+ namespace MongoDB . Benchmarks ;
25+
26+ public static class BenchmarkHelper
2527{
26- public static class BenchmarkHelper
27- {
28- public const string DataFolderPath = "../../../../../../../data/" ;
28+ public const string DataFolderPath = "../../../../../../../data/" ;
2929
30- public static void AddFilesToQueue ( ConcurrentQueue < ( string , int ) > filesQueue , string directoryPath , string fileNamePrefix , int fileCount )
30+ public static void AddFilesToQueue ( ConcurrentQueue < ( string , int ) > filesQueue , string directoryPath , string fileNamePrefix , int fileCount )
31+ {
32+ var addingLDJSONfiles = fileNamePrefix == "ldjson" ;
33+ for ( int i = 0 ; i < fileCount ; i ++ )
3134 {
32- var addingLDJSONfiles = fileNamePrefix == "ldjson" ;
33- for ( int i = 0 ; i < fileCount ; i ++ )
34- {
35- var fileName = addingLDJSONfiles ? $ "{ fileNamePrefix } { i : D3} .txt" : $ "{ fileNamePrefix } { i : D2} .txt";
36- filesQueue . Enqueue ( ( $ "{ directoryPath } /{ fileName } ", i ) ) ; // enqueue complete filepath and filenumber
37- }
35+ var fileName = addingLDJSONfiles ? $ "{ fileNamePrefix } { i : D3} .txt" : $ "{ fileNamePrefix } { i : D2} .txt";
36+ filesQueue . Enqueue ( ( $ "{ directoryPath } /{ fileName } ", i ) ) ; // enqueue complete filepath and filenumber
3837 }
38+ }
3939
40- public static double CalculateCompositeScore ( IEnumerable < BenchmarkResult > benchmarkResults , string benchmarkCategory )
41- {
42- var identifiedBenchmarksScores = benchmarkResults
43- . Where ( benchmark => benchmark . Categories . Contains ( benchmarkCategory ) )
44- . Select ( benchmark => benchmark . Score ) . ToArray ( ) ;
45-
46- if ( identifiedBenchmarksScores . Any ( ) )
47- {
48- return identifiedBenchmarksScores . Average ( ) ;
49- }
50-
51- return 0 ;
52- }
40+ public static double CalculateCompositeScore ( IEnumerable < BenchmarkResult > benchmarkResults , string benchmarkCategory )
41+ {
42+ var identifiedBenchmarksScores = benchmarkResults
43+ . Where ( benchmark => benchmark . Categories . Contains ( benchmarkCategory ) )
44+ . Select ( benchmark => benchmark . Score ) . ToArray ( ) ;
5345
54- public static void CreateEmptyDirectory ( string path )
46+ if ( identifiedBenchmarksScores . Any ( ) )
5547 {
56- if ( Directory . Exists ( path ) )
57- {
58- Directory . Delete ( path , true ) ;
59- }
60- Directory . CreateDirectory ( path ) ;
48+ return identifiedBenchmarksScores . Average ( ) ;
6149 }
6250
63- public static BsonDocument ReadExtendedJson ( string resourcePath )
64- {
65- var extendedJson = File . ReadAllText ( DataFolderPath + resourcePath ) ;
66- return BsonDocument . Parse ( extendedJson ) ;
67- }
51+ return 0 ;
52+ }
6853
69- public static byte [ ] ReadExtendedJsonToBytes ( string resourcePath )
54+ public static void CreateEmptyDirectory ( string path )
55+ {
56+ if ( Directory . Exists ( path ) )
7057 {
71- var extendedJson = File . ReadAllText ( DataFolderPath + resourcePath ) ;
72- var document = BsonDocument . Parse ( extendedJson ) ;
73- return document . ToBson ( ) ;
58+ Directory . Delete ( path , true ) ;
7459 }
60+ Directory . CreateDirectory ( path ) ;
61+ }
7562
76- public static class MongoConfiguration
77- {
78- public const string PerfTestDatabaseName = "perftest" ;
79- public const string PerfTestCollectionName = "corpus" ;
63+ public static BsonDocument ReadExtendedJson ( string resourcePath )
64+ {
65+ var extendedJson = File . ReadAllText ( DataFolderPath + resourcePath ) ;
66+ return BsonDocument . Parse ( extendedJson ) ;
67+ }
8068
81- public static IMongoClient CreateClient ( )
82- {
83- var mongoUri = Environment . GetEnvironmentVariable ( "MONGODB_URI" ) ;
84- var settings = mongoUri != null ? MongoClientSettings . FromConnectionString ( mongoUri ) : new ( ) ;
85- settings . ClusterSource = DisposingClusterSource . Instance ;
69+ public static byte [ ] ReadExtendedJsonToBytes ( string resourcePath )
70+ {
71+ var extendedJson = File . ReadAllText ( DataFolderPath + resourcePath ) ;
72+ var document = BsonDocument . Parse ( extendedJson ) ;
73+ return document . ToBson ( ) ;
74+ }
75+
76+ public static class MongoConfiguration
77+ {
78+ public const string PerfTestDatabaseName = "perftest" ;
79+ public const string PerfTestCollectionName = "corpus" ;
80+
81+ public static IMongoClient CreateClient ( )
82+ {
83+ var mongoUri = Environment . GetEnvironmentVariable ( "MONGODB_URI" ) ;
84+ var settings = mongoUri != null ? MongoClientSettings . FromConnectionString ( mongoUri ) : new ( ) ;
85+ settings . ClusterSource = DisposingClusterSource . Instance ;
8686
87- var client = new MongoClient ( settings ) ;
88- client . DropDatabase ( PerfTestDatabaseName ) ;
87+ var client = new MongoClient ( settings ) ;
88+ client . DropDatabase ( PerfTestDatabaseName ) ;
8989
90- return client ;
91- }
90+ return client ;
9291 }
9392 }
94- }
93+ }
0 commit comments