Canvas vs Labels - page 13

 
Nikolai Semko:

Ah, well, then it's normal at all.
I also have one canvas on my gif, and it's the panel that eats up the least amount of resources, because I don't have to redraw it as often and catch the moment a new bar comes in.

Great! Everything is flying!

And at low speed, it updates without skipping a beat.
 
Dmitry Fedoseev:
Found the right files. It's not clear where, where and when to look at the numbers, but even without that one can see that the canvas is much slower, and it's not just a canvas instead of one lebble, but one canvas instead of a bunch of labels.

Run expert CanvasVsLabels.mq5, select display typeoutType, enable limit_fps, set, nIterations, it is 10000 by default. This is enough, you do not need to change it. Then the results will be similar to the ones presented here: https://www.mql5.com/ru/forum/364640/page11#comment_21301589.

Now for the results. Min delay,Mid delay andMax delay are the minimum, average and maximum delays, respectively, for one run. Total, is the total time for the total number ofnIterations passes.

Once again, here is a table with comparisonresults

Canvas unlimited fps Canvas limited fps Labels unlimited fps Labels limited fps
Min delay (μs) 1530 1 18 0
Mid delay (μs) 7674 4086 48 7
Max delay (μs) 11967 11093 785 286
Total (μs) 77727510 29452299 39648984 27439654


Exactly the same measurements can be taken in the tester, as the examiner is designed to do so. But I haven't done them yet. I will do so when I have some free time. I plan to experiment with a display of many BitmabLabels in the future.

 

Forum on trading, automated trading systems and strategy testing

Canvas vs Labels

fxsaber, 2021.03.13 19:26

I'm the only one with this kind of result?

fxsaber:

Takes away 15-20%. Apparently, my video card is too slow.

Turns out ResourceReadImage is very slow. Got rid of it - got zero load.

 

Once again I publish the comparison table, but this time with histograms.

Canvas unlimited fps Canvas limited fps Labels unlimited fps Labels limited fps
Min delay (μs) 1530 1 18 0
Mid delay (μs) 7674 4086 48 7
Max delay (μs) 11967 11093 785 286
Total (μs) 77727510 29452299 39648984 27439654


Comparison of average delay values per pass

Mid delay

Which for some reason were not comparable to the total running time (Total)...

Comparison of total running time

Total

Measurements showed that Canvas based display with limited FPS (Canvas unlimited FPS) is a bit slower than Labels based display with limited FPS (Labels unlimited FPS). But in general they are both suitable for displaying information from highly loaded processes.

How to run the Expert Advisor to take measurements

Input parameters

  1. Select outType from the Canvas or Labels drop-down list
  2. Set limit_fps on or off.
  3. Confirm your selection
  4. Press Start button to start measurements in the chart

Starting measurements

The Expert Advisor can take measurements in the visual tester in exactly the same way. However, the date range should be set in the tester settings so as to have at least as many bars in the history as the value of the input parameternIterations.

More information, as well as sources, can be found in the description of Chart Display library:https://www.mql5.com/ru/code/33898

Library specially modified for measurements:https://www.mql5.com/ru/code/download/33898/chartdisplay.mqh

Universal expert for measurement:https://www.mql5.com/ru/code/download/33898/canvasvslabels.mq5

For more details see KB: https://www.mql5.com/ru/code/33898


I would like to add more correct measurements, made with the new Expert Advisor in the very first post of this thread. As those measurements, which are there at the moment, are not correct. But the first message, unfortunately, cannot be edited anymore. I ask moderators to add more correct measurements to the beginning, and to mark the ones that are there now as irrelevant.

Дисплей с оптимизацией для вывода текста в чарт по типу консоли
Дисплей с оптимизацией для вывода текста в чарт по типу консоли
  • www.mql5.com
Данная библиотека позволяет создавать дисплеи для удобного вывода текстовой информации в чарт с наиболее оптимальной скоростью
 
fxsaber:

It turned out that ResourceReadImage is very slow. Got rid of it - zero load.

Seriously?
Surprise for me.
How much slower than copying an ordinary uint array of the same size?
 
Mihail Matkovskij:

Running expert CanvasVsLabels.mq5...

What's the point? I don't want to dig into the code right now. How are these values calculated? If you test in the tester, you should measure the total time spent on the run and nothing else, but not the performance of individual code fragments. In the extreme case, do not count the inite. And here, without measuring, you can see that kanvas is slower. I don't know, maybe I have some kind of anomaly...

 
Nikolai Semko:
Really?
Surprise for me.
How much slower than copying a normal uint array of the same size?

With calling it was about 15% load, without - zero.

 
Dmitry Fedoseev:

What's the point? I don't want to dig into the code right now. How are these figures calculated? If you test in the tester like that, you should measure the total time spent on the run and nothing else, and not the performance of separate code fragments. In the extreme case, do not count the inite. And here, without measuring, you can see that kanvas is slower. I don't know, maybe I have some kind of anomaly...

I don't want to dig into the code. I don't want to take my word for it either. :) I don't know how to explain it to you. Telling you from beginning to end how I wrote all the code... It'd be a whole article. :)

And there's nothing to understand about how an expert makes measurements at all.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void run() {
  MqlRates rates[];
  int digits = (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS);
  ulong start, min, mid, max;
  ulong last, delay; 
  static ulong totalDelays = 0;
  static int nTick = 0;
  ulong first;
  if (!triggerBtn.State())
    return;
  start = GetMicrosecondCount();
  min = INT_MAX; mid = 0; max = 0;
  if (CopyRates(NULL, PERIOD_CURRENT, 0, nIterations, rates) != nIterations) {
    triggerBtn.State(false);
    triggerBtn.setText("Start");
    Print("Not enough quotes!");
    Comment("Not enough quotes!");
    return;
  }
  for (int i = nIterations - 1; i >= 0 && triggerBtn.State(); i--) {
    first = GetMicrosecondCount();
    
    display.push();
    display.setText(concatenate(i));
    display.update();
    
    last = GetMicrosecondCount();
    delay = last - first;
    if (delay < min)
      min = delay;
    if (delay > max)
      max = delay;
    nTick++;
    totalDelays += delay;
    mid = totalDelays / nTick;
    Comment("Min delay: " + (string)min + " μs\n"
            "Mid delay: " + (string)mid + " μs\n"
            "Max delay: " + (string)max + " μs\n"
            "Total: " + (string)(GetMicrosecondCount() - start) + " μs" + " \n"
            "Completed: " + (string)(int)(100.0 / nIterations * (nIterations - i)) + "%");
  }
  
  printf("Min delay: %d μs", min);
  printf("Mid delay: %d μs", mid);
  printf("Max delay: %d μs", max);
  printf("Total: %d μs", GetMicrosecondCount() - start);
  triggerBtn.State(false);
  triggerBtn.setText("Start");
  ChartRedraw();
}
Total is calculated at the end of the loop and min, mid and max in the body of the loop, after display.push, display.setText and display.update. Nothing complicated, if you sit down and take a good look at everything, you can get at least to the source code of Kanvas and Labels. There's nothing complicated there either, by the way. Except for the methods that draw Bezier curves and the like in Kanvas.
 
Dmitry Fedoseev:

And here, without measurements, you can see that the kanvas is slower. I don't know, maybe I have some kind of anomaly...

You need to tell me at what input parameters Kanvas is slow. If limit_fps: false, then it's obvious... :)

 
fxsaber:

It turned out that ResourceReadImage is very slow. Got rid of it and got zero load.

If you read from a resource saved at compile time, you have to do it once.

Resources are compressed at compile time.

Reason: