//+------------------------------------------------------------------+ //| Introsort_benchmark.mq5 | //| Copyright © 2018, Amr Ali | //| https://www.mql5.com/en/users/amrali | //+------------------------------------------------------------------+ #include "Introsort.mqh" #define SIZE 10*1000*1000 // 10 millions int arr1[SIZE]; int arr2[SIZE]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { //--- Prepare unsorted arrays. for(int i = 0; i < SIZE; i++) { arr1[i] = MathRand(); arr2[i] = arr1[i]; } //--- ArraySort() benchmark. uint t1 = GetTickCount(); ArraySort(arr1); uint ticks1 = GetTickCount() - t1; //--- Introsort() benchmark. uint t2 = GetTickCount(); Introsort(arr2); uint ticks2 = GetTickCount() - t2; //--- Display results. PrintFormat("Sorting %d integers: ", SIZE); PrintFormat("ArraySort() -> %u millisec", ticks1); PrintFormat("Introsort() -> %u millisec", ticks2); PrintFormat("Speed-up factor is %.1fx", (double)ticks1/ticks2); PrintFormat("%s", ArrayCompare(arr1, arr2) ? "Introsort: invalid sort order.": ""); } //+------------------------------------------------------------------+ // sample output: /* Sorting 10000000 integers: ArraySort() -> 1095 millisec Introsort() -> 666 millisec Speed-up factor is 1.6x */