forked from amrali/CBitBuffer
		
	
		
			
				
	
	
		
			58 lines
		
	
	
		
			No EOL
		
	
	
		
			4.7 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			No EOL
		
	
	
		
			4.7 KiB
		
	
	
	
		
			MQL5
		
	
	
	
	
	
#property script_show_inputs
 | 
						|
 | 
						|
input datetime inFrom = D'2024.12.01';
 | 
						|
 | 
						|
//#include "TicksShort.mqh" // Короткий формат хранения тиков.
 | 
						|
#include "TicksShortLite.mqh"
 | 
						|
 | 
						|
// Возвращает размер массива в байтах.
 | 
						|
template <typename T>
 | 
						|
ulong GetSize( const T &Array[] ) { return((ulong)sizeof(T) * ArraySize(Array)); }
 | 
						|
 | 
						|
template <typename T1, typename T2>
 | 
						|
double Criterion( const T1 &Decompression[], const T2 &Compression[], const ulong Interval )
 | 
						|
{
 | 
						|
  const double Performance = (double)ArraySize(Decompression) / Interval;
 | 
						|
 | 
						|
  return(Performance * ((double)GetSize(Decompression) / GetSize(Compression)));
 | 
						|
}
 | 
						|
 | 
						|
void OnStart()
 | 
						|
{
 | 
						|
  MqlTick Ticks[]; // Для исходных тиков.
 | 
						|
 | 
						|
  if (CopyTicksRange(_Symbol, Ticks, COPY_TICKS_ALL,(ulong)inFrom * 1000) > 0)
 | 
						|
  {
 | 
						|
    //TICK_SHORT Ticks2[]; // Для сжатых тиков.
 | 
						|
    uchar Ticks2[];
 | 
						|
 | 
						|
    ulong Interval = GetMicrosecondCount();
 | 
						|
    TICKS_SHORT::Compress(Ticks, Ticks2); // Сжали.
 | 
						|
    Interval = GetMicrosecondCount() - Interval;
 | 
						|
    const double Performance = (double)ArraySize(Ticks) / Interval;
 | 
						|
 | 
						|
    // https://www.mql5.com/ru/forum/490384#comment_57497700
 | 
						|
    long n1 = ArraySize(Ticks) * (long)sizeof(MqlTick);
 | 
						|
    //long n2 = ArraySize(Ticks2) * (long)sizeof(TICK_SHORT);
 | 
						|
    long n2 = ArraySize(Ticks2) * (long)sizeof(uchar);
 | 
						|
    PrintFormat("Compressed %I64i bytes into %I64i bytes ==> %.2f%%",n1,n2,(double)n2/n1*100);
 | 
						|
 | 
						|
    Print("Compress performance: " + DoubleToString(Performance * sizeof(MqlTick) / 1.04858, 0) + " MB/s");
 | 
						|
    Print("Compress performance: " + DoubleToString(Performance, 1) + " Ticks (millions)/sec.");
 | 
						|
    Print("Compress performance criterion: " + DoubleToString(Criterion(Ticks, Ticks2, Interval), 1));
 | 
						|
 | 
						|
    MqlTick Ticks3[]; // Для разжатых тиков.
 | 
						|
 | 
						|
    ulong Interval2 = GetMicrosecondCount();
 | 
						|
    TICKS_SHORT::Decompress(Ticks2, Ticks3); // Разжали.
 | 
						|
 | 
						|
    Interval2 = GetMicrosecondCount() - Interval2;
 | 
						|
    const double Performance2 = (double)ArraySize(Ticks3) / Interval2;
 | 
						|
 | 
						|
    Print("Decompress performance: " + DoubleToString(Performance2 * sizeof(MqlTick) / 1.04858, 0) + " MB/s");
 | 
						|
    Print("Decompress performance: " + DoubleToString(Performance2, 1) + " Ticks (millions)/sec.");
 | 
						|
    Print("Decompress performance criterion: " + DoubleToString(Criterion(Ticks3, Ticks2, Interval2), 1));
 | 
						|
 | 
						|
    Print("Correct = " + (string)TICKS_SHORT::IsEqual(Ticks, Ticks3)); // Сравнили.
 | 
						|
  }
 | 
						|
} |