Libraries: Benchmark - page 2

 
amrali #:

Then, you need the code profiler to spot bottlenecks in your program, not the benchmarks.

Benchmarks have a specific use scenario, the same as that in the description above.

In real time, bursts of slowdown can occur while the release version is running. It is important to understand where and when this happens.

 
Comments that do not relate to this topic, have been moved to "Libraries: MQL Plus Enhanced Debugging Support".
 
fxsaber #:

In real time, bursts of slowdown can occur while the release version is running. It is important to understand where and when this happens.

Then, the next step after you spotted the place of bottlenecks (using the profiler) is to test some other variations of the problem code. This is where benchmark macros become useful.

 
amrali #:

Then, the next step after you spotted the place of bottlenecks (using the profiler) is to test some other variations of the problem code. This is where benchmark macros become useful.

I suggest you try to solve the following problem.

Forum on trading, automated trading systems and testing trading strategies

Libraries: MQL Plus Enhanced Debugging Support

fxsaber, 2023.04.25 20:39

Please show an example of measurement in the code below.

int f1() { Sleep(100); return(1); }
int f2() { Sleep(200); return(2); }
int f3() { Sleep(300); return(3); }

int g()
{
  return((f1() + f2() + f3() == 6) ?
                       f1() * f2() : 0);
}

void OnStart()
{
  if (g() == 2)   
    Print(f3() == 3);

  Print(f1());
  Print(f2());
}

It is necessary to measure the execution time of the pieces of code highlighted in yellow.

 
fxsaber #:

I suggest you try to solve the following problem.

In a real program that has many calls, the best is to isolate each function's execution time, separately. 

Any combinations of functions (as in your example, or even more complex) can be resolved in terms of its elementary components.

#include <mql5_lib\base.mqh>
void OnStart()
  {
   int sum = 0;
   TimeIt(sum += f1());
   TimeIt(sum += f2());
   TimeIt(sum += f3());
   Print("sum=",sum);
  }

// sum+=f1() -> 109075.000 µsec/call
// sum+=f2() -> 202796.500 µsec/call
// sum+=f3() -> 311990.000 µsec/call

For example, if you find function f3() has the longest time, then, it is better optimize/replace it.

 
amrali #:

In a real program that has many calls, the best is to isolate each function's execution time, separately. 

Any combinations of functions (as in your example, or even more complex) can be resolved in terms of its elementary components.

For example, if you find function f3() has the longest time, then, it is better optimize/replace it.

I expected to see something like this.

Forum on trading, automated trading systems and testing trading strategies

Libraries: MQL Plus Enhanced Debugging Support

fxsaber, 2023.04.26 14:58

int f1() { Sleep(100); return(1); }
int f2() { Sleep(200); return(2); }
int f3() { Sleep(300); return(3); }

int g()
{
  return(TimeIt(f1() + f2() + f3() == 6) ?
                       TimeIt(f1() * f2()) : 0);
}

void OnStart()
{
  if (TimeIt(g()) == 2)   
    Print(TimeIt(f3() == 3));

  TimeIt(
  Print(f1());
  Print(f2());)
}
 
fxsaber #:

I expected to see something like this.

ah..Then do not. Use your library. Mine does not fit.

 
amrali #:

ah..Then do not. Use your library. Mine does not fit.

I propose to improve the usability of your library.

 
fxsaber #:

I propose to improve the usability of your library.

I think you have some confusion about two separate concepts: micro-benchmarking vs macro-benchmarking.

According to this article https://www.adservio.fr/post/what-is-microbenchmarking

"If you're looking to track the overall performance of your application or otherwise take a "big picture" point of view to a problem, you might not find microbenchmarks suited to your use case. Microbenchmarks deal with the smallest of all benchmarks, and they represent a very simple and easy-to-define metric that tracks and measures the performance of a small and specific piece of code. In contrast of macro-benchmarking, which is the process of running a computer program to evaluate how well the runtime environment performs. Source code instrumentation: This technique is used to modify source code to insert appropriate code (usually conditionally compiled so you can turn it off). Instrumentation is limited by execution coverage. If the program never reaches a particular point of execution, then instrumentation at that point collects no data. For instance, if a word processor application is instrumented, but the user never activates the print feature, then the instrumentation can say nothing about the routines which are used exclusively by the printing feature."

Edit

I missed including the citation source.

What fits your previous example is code instrumentation, tracing and profiling which was not the main intent (actually outside the scope) of my library. The process of performance testing usually begins with macro-benchmarking to identify hot code paths, then use micro-benchmarks to test other faster alternatives for slow routines in the program.

What is Micro-benchmarking?
What is Micro-benchmarking?
  • www.adservio.fr
A microbenchmark is a program that tracks and measures the performance of a single well-defined task such as elapsed time, rate of operation, bandwidth, etc.
 
I have gone thorough a lot of similar code but this is good one and well commented. I appreciate the programmer. Regards