@@ -54,9 +54,43 @@ private enum BenchmarkSettingsStatus : int {
54
54
55
55
// CPU benchmarking helpers
56
56
private class CPUBenchmarkStatus {
57
- public bool HasAlreadyBenchmarked = false ; // after first benchmark set to true
58
- public double BenchmarkSpeed ;
59
- public int LessTreads = 0 ;
57
+ private class benchmark {
58
+ public benchmark ( int lt , double bench ) {
59
+ LessTreads = lt ;
60
+ Benchmark = bench ;
61
+ }
62
+ public readonly int LessTreads ;
63
+ public readonly double Benchmark ;
64
+ }
65
+ public CPUBenchmarkStatus ( int max_threads ) {
66
+ _max_threads = max_threads ;
67
+ }
68
+
69
+ public bool HasTest ( ) {
70
+ return _cur_less_threads < _max_threads ;
71
+ }
72
+
73
+ public void SetNextSpeed ( double speed ) {
74
+ if ( HasTest ( ) ) {
75
+ _benchmarks . Add ( new benchmark ( _cur_less_threads , speed ) ) ;
76
+ ++ _cur_less_threads ;
77
+ }
78
+ }
79
+
80
+ public void FindFastest ( ) {
81
+ _benchmarks . Sort ( ( a , b ) => - a . Benchmark . CompareTo ( b . Benchmark ) ) ;
82
+ }
83
+ public double GetBestSpeed ( ) {
84
+ return _benchmarks [ 0 ] . Benchmark ;
85
+ }
86
+ public int GetLessThreads ( ) {
87
+ return _benchmarks [ 0 ] . LessTreads ;
88
+ }
89
+
90
+ private readonly int _max_threads ;
91
+ private int _cur_less_threads = 0 ;
92
+ private List < benchmark > _benchmarks = new List < benchmark > ( ) ;
93
+ public int LessTreads { get { return _cur_less_threads ; } }
60
94
public int Time ;
61
95
}
62
96
private CPUBenchmarkStatus __CPUBenchmarkStatus = null ;
@@ -458,8 +492,8 @@ void NextBenchmark() {
458
492
459
493
if ( _currentDevice != null && _currentAlgorithm != null ) {
460
494
_currentMiner = MinerFactory . CreateMiner ( _currentDevice , _currentAlgorithm ) ;
461
- if ( _currentAlgorithm . MinerBaseType == MinerBaseType . XmrStackCPU && _currentAlgorithm . NiceHashID == AlgorithmType . CryptoNight && string . IsNullOrEmpty ( _currentAlgorithm . ExtraLaunchParameters ) ) {
462
- __CPUBenchmarkStatus = new CPUBenchmarkStatus ( ) ;
495
+ if ( _currentAlgorithm . MinerBaseType == MinerBaseType . XmrStackCPU && _currentAlgorithm . NiceHashID == AlgorithmType . CryptoNight && string . IsNullOrEmpty ( _currentAlgorithm . ExtraLaunchParameters ) && _currentAlgorithm . ExtraLaunchParameters . Contains ( "enable_ht=true" ) == false ) {
496
+ __CPUBenchmarkStatus = new CPUBenchmarkStatus ( Globals . ThreadsPerCPU ) ;
463
497
_currentAlgorithm . LessThreads = __CPUBenchmarkStatus . LessTreads ;
464
498
} else {
465
499
__CPUBenchmarkStatus = null ;
@@ -553,20 +587,13 @@ public void OnBenchmarkComplete(bool success, string status) {
553
587
_bechmarkedSuccessCount += success ? 1 : 0 ;
554
588
bool rebenchSame = false ;
555
589
if ( success && __CPUBenchmarkStatus != null && CPUAlgos . Contains ( _currentAlgorithm . NiceHashID ) && _currentAlgorithm . MinerBaseType == MinerBaseType . XmrStackCPU ) {
556
- if ( __CPUBenchmarkStatus . HasAlreadyBenchmarked && __CPUBenchmarkStatus . BenchmarkSpeed > _currentAlgorithm . BenchmarkSpeed ) {
557
- rebenchSame = false ;
558
- _currentAlgorithm . BenchmarkSpeed = __CPUBenchmarkStatus . BenchmarkSpeed ;
559
- _currentAlgorithm . LessThreads -- ;
560
- } else {
561
- __CPUBenchmarkStatus . HasAlreadyBenchmarked = true ;
562
- __CPUBenchmarkStatus . BenchmarkSpeed = _currentAlgorithm . BenchmarkSpeed ;
563
- __CPUBenchmarkStatus . LessTreads ++ ;
564
- if ( __CPUBenchmarkStatus . LessTreads < Globals . ThreadsPerCPU ) {
565
- _currentAlgorithm . LessThreads = __CPUBenchmarkStatus . LessTreads ;
566
- rebenchSame = true ;
567
- } else {
568
- rebenchSame = false ;
569
- }
590
+ __CPUBenchmarkStatus . SetNextSpeed ( _currentAlgorithm . BenchmarkSpeed ) ;
591
+ rebenchSame = __CPUBenchmarkStatus . HasTest ( ) ;
592
+ _currentAlgorithm . LessThreads = __CPUBenchmarkStatus . LessTreads ;
593
+ if ( rebenchSame == false ) {
594
+ __CPUBenchmarkStatus . FindFastest ( ) ;
595
+ _currentAlgorithm . BenchmarkSpeed = __CPUBenchmarkStatus . GetBestSpeed ( ) ;
596
+ _currentAlgorithm . LessThreads = __CPUBenchmarkStatus . GetLessThreads ( ) ;
570
597
}
571
598
}
572
599
0 commit comments