@@ -8,27 +8,47 @@ namespace BitFaster.Caching.ThroughputAnalysis
88{
99 public class ConfigFactory
1010 {
11- const double s = 0.86 ; // Zipf s parameter, controls distribution
12- const int n = 500 ; // number of unique items for Zipf
13- const int maxThreads = 52 ;
14- const int sampleCount = 2000 ;
11+ const double s = 0.86 ; // Zipf s parameter, controls distribution
1512
16- public static ( ThroughputBenchmarkBase , IThroughputBenchConfig , int ) Create ( Mode mode , int repeatCount )
13+ public static ( ThroughputBenchmarkBase , IThroughputBenchConfig , int ) Create ( Mode mode , int cacheSize , int maxThreads )
1714 {
15+ int iterations = GetIterationCount ( cacheSize ) ;
16+ int samples = GetSampleCount ( cacheSize ) ;
17+ int n = cacheSize ; // number of unique items for Zipf
18+
1819 switch ( mode )
1920 {
2021 case Mode . Read :
21- return ( new ReadThroughputBenchmark ( ) , new ZipfConfig ( repeatCount , sampleCount , s , n ) , n ) ;
22+ return ( new ReadThroughputBenchmark ( ) , new ZipfConfig ( iterations , samples , s , n ) , cacheSize ) ;
2223 case Mode . ReadWrite :
2324 // cache holds 10% of all items
24- return ( new ReadThroughputBenchmark ( ) , new ZipfConfig ( repeatCount , sampleCount , s , n ) , n / 10 ) ;
25+ cacheSize = cacheSize / 10 ;
26+ return ( new ReadThroughputBenchmark ( ) , new ZipfConfig ( iterations , samples , s , n ) , cacheSize ) ;
2527 case Mode . Update :
26- return ( new UpdateThroughputBenchmark ( ) , new ZipfConfig ( repeatCount , sampleCount , s , n ) , n ) ;
28+ return ( new UpdateThroughputBenchmark ( ) , new ZipfConfig ( iterations , samples , s , n ) , cacheSize ) ;
2729 case Mode . Evict :
28- return ( new ReadThroughputBenchmark ( ) , new EvictionConfig ( repeatCount , sampleCount , maxThreads ) , n ) ;
30+ return ( new ReadThroughputBenchmark ( ) , new EvictionConfig ( iterations , samples , maxThreads ) , cacheSize ) ;
2931 }
3032
3133 throw new InvalidOperationException ( ) ;
3234 }
35+
36+ private static int GetIterationCount ( int cacheSize ) => cacheSize switch
37+ {
38+ < 500 => 400 ,
39+ < 5_000 => 200 ,
40+ < 10_000 => 100 ,
41+ < 100_000 => 50 ,
42+ < 1_000_000 => 25 ,
43+ < 10_000_000 => 5 ,
44+ _ => 1
45+ } ;
46+
47+ private static int GetSampleCount ( int cacheSize ) => cacheSize switch
48+ {
49+ < 5_000 => cacheSize * 4 ,
50+ < 5_000_000 => cacheSize * 2 ,
51+ _ => cacheSize
52+ } ;
3353 }
3454}
0 commit comments