46 lines
3.1 KiB
MQL5
46 lines
3.1 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| speed_benchmark.mq5 |
|
|
//| Copyright © 2018, Amr Ali |
|
|
//| https://www.mql5.com/en/users/amrali |
|
|
//+------------------------------------------------------------------+
|
|
#include "Xoshiro256.mqh"
|
|
//--- the random number generator object
|
|
Xoshiro256 prng;
|
|
|
|
#define ITER (500*1000*1000) // 500 millions
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void OnStart()
|
|
{
|
|
//--- MathRand() benchmark.
|
|
uint t1 = GetTickCount();
|
|
for(int i = 0; i < ITER; i++)
|
|
{
|
|
MathRand();
|
|
}
|
|
uint ticks1 = GetTickCount() - t1;
|
|
|
|
//--- Xoshiro256 benchmark.
|
|
uint t2 = GetTickCount();
|
|
for(int i = 0; i < ITER; i++)
|
|
{
|
|
prng.RandomInteger();
|
|
}
|
|
uint ticks2 = GetTickCount() - t2;
|
|
|
|
//--- Display results.
|
|
PrintFormat("Generating %d random integers: ", ITER);
|
|
PrintFormat("MathRand() -> %u millisec", ticks1);
|
|
PrintFormat("Xoshiro256 -> %u millisec", ticks2);
|
|
PrintFormat("Speed-up factor is %.1fx", (double)ticks1/ticks2);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
// sample output:
|
|
/*
|
|
Generating 500000000 random integers:
|
|
MathRand() -> 968 millisec
|
|
Xoshiro256 -> 422 millisec
|
|
Speed-up factor is 2.3x
|
|
*/
|