//+------------------------------------------------------------------+ //| TestStatBenchmark.mq5 | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2000-2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //+------------------------------------------------------------------+ //| Structure for benchmark information | //+------------------------------------------------------------------+ struct benchmark_info { //--- propability density calculation times double pdf_time_min; double pdf_time_max; double pdf_time_mean; double pdf_time_median; double pdf_time_stddev; double pdf_time_avgdev; //--- cumulative distribution calculation times double cdf_time_min; double cdf_time_max; double cdf_time_mean; double cdf_time_median; double cdf_time_stddev; double cdf_time_avgdev; //--- quantile calculation times double quantile_time_min; double quantile_time_max; double quantile_time_mean; double quantile_time_median; double quantile_time_stddev; double quantile_time_avgdev; //--- random variable calculation times double random_time_min; double random_time_max; double random_time_mean; double random_time_median; double random_time_stddev; double random_time_avgdev; }; #define AverageCount 1000 //+------------------------------------------------------------------+ //| ShowBenchmarkInfo | //+------------------------------------------------------------------+ void ShowBenchmarkInfo(const string test_info,benchmark_info &benchmark) { PrintFormat("%s time (microseconds): pdf_mean=%4.2f, pdf_median=%4.2f, pdf_min=%4.2f, pdf_max=%4.2f, pdf_stddev=%4.2f, pdf_avgdev=%4.2f", test_info,benchmark.pdf_time_mean,benchmark.pdf_time_median,benchmark.pdf_time_min,benchmark.pdf_time_max,benchmark.pdf_time_stddev,benchmark.pdf_time_avgdev); PrintFormat("%s time (microseconds): cdf_mean=%4.2f, cdf_median=%4.2f, cdf_min=%4.2f, cdf_max=%4.2f, cdf_stddev=%4.2f, cdf_avgdev=%4.2f", test_info,benchmark.cdf_time_mean,benchmark.cdf_time_median,benchmark.cdf_time_min,benchmark.cdf_time_max,benchmark.cdf_time_stddev,benchmark.cdf_time_avgdev); PrintFormat("%s time (microseconds): quantile_mean=%4.2f, quantile_median=%4.2f, quantile_min=%4.2f, quantile_max=%4.2f, quantile_stddev=%4.2f, quantile_avgdev=%4.2f", test_info,benchmark.quantile_time_mean,benchmark.quantile_time_median,benchmark.quantile_time_min,benchmark.quantile_time_max,benchmark.quantile_time_stddev,benchmark.quantile_time_avgdev); PrintFormat("%s time (microseconds): random_mean=%4.2f, random_median=%4.2f, random_min=%4.2f, random_max=%4.2f, random_stddev=%4.2f, random_avgdev=%4.2f", test_info,benchmark.random_time_mean,benchmark.random_time_median,benchmark.random_time_min,benchmark.random_time_max,benchmark.random_time_stddev,benchmark.random_time_avgdev); } //+------------------------------------------------------------------+ //| CalculateStatisticalProperties | //+------------------------------------------------------------------+ void CalculateStatisticalProperties(benchmark_info &benchmark,double &pdf_times[],double &cdf_times[],double &quantile_times[],double &random_times[]) { //--- calculate statistical properties for calculation time: min,max,mean,median,standard and average deviations //--- probability density benchmark.pdf_time_min=MathMin(pdf_times); benchmark.pdf_time_max=MathMax(pdf_times); benchmark.pdf_time_mean=MathMean(pdf_times); benchmark.pdf_time_median=MathMedian(pdf_times); benchmark.pdf_time_stddev=MathStandardDeviation(pdf_times); benchmark.pdf_time_avgdev=MathAverageDeviation(pdf_times); //--- cumulative distribution benchmark.cdf_time_min=MathMin(cdf_times); benchmark.cdf_time_max=MathMax(cdf_times); benchmark.cdf_time_mean=MathMean(cdf_times); benchmark.cdf_time_median=MathMedian(cdf_times); benchmark.cdf_time_stddev=MathStandardDeviation(cdf_times); benchmark.cdf_time_avgdev=MathAverageDeviation(cdf_times); //--- quantile benchmark.quantile_time_min=MathMin(quantile_times); benchmark.quantile_time_max=MathMax(quantile_times); benchmark.quantile_time_mean=MathMean(quantile_times); benchmark.quantile_time_median=MathMedian(quantile_times); benchmark.quantile_time_stddev=MathStandardDeviation(quantile_times); benchmark.quantile_time_avgdev=MathAverageDeviation(quantile_times); //--- random values benchmark.random_time_min=MathMin(random_times); benchmark.random_time_max=MathMax(random_times); benchmark.random_time_mean=MathMean(random_times); benchmark.random_time_median=MathMedian(random_times); benchmark.random_time_stddev=MathStandardDeviation(random_times); benchmark.random_time_avgdev=MathAverageDeviation(random_times); return; } //+------------------------------------------------------------------+ //| CalculateBenchmarkBinomial | //+------------------------------------------------------------------+ bool CalculateBenchmarkBinomial(benchmark_info &benchmark_binomial,int &tests_performed,int &tests_passed) { tests_performed++; //--- Binomial distribution parameters const int N=50; const double probability=0.1; //--- prepare x values double x_values[]; ArrayResize(x_values,N); for(int i=0; i