Canvas vs Labels

 

I would like to present you a comparison of the speed of displays for displaying text in the chart, created using different methods. The first variant of the display I made using CCanvas class, the second one I created on labels (CChartObjectLabel). All classes were taken from the standard library. This idea came to me when I created a display on CCanvas and it significantly slowed down my Expert Advisor. At the same time, some programmers claimed that I was wrong andCCanvas, and to be more accurate, OBJ_BITMAP_LABEL is very fast, faster than all methods of displaying information in the chart available in MetaTrader.So, I decided to check it experimentally. So, the moment of truth.

Operation of the display with output inCCanvas

CCanvas

CPU load at this moment

CPU

Operation of display withCChartObjectLabel output

Labels

Operation ofCChartObjectLabel with CChartObjectLabel with speed optimizing mode enabled (I will tell you about it below).

Labels Optimized

Now for the time values. Total is the total running time of the test Expert Advisor. Min delay,Mid delay andMax delay are delayperiods on ticks. But they cannot always be obtained correctly, despite the fact that I checked the code, there were no errors. I think it has to do with the function GetTickCount64 in the tester. But it's an insignificant problem. The main thing is that it shows the total time.

Now let me briefly speak about optimization of the display on labels. The thing is that in order for the text to appear on the screen you need to display lines from a special array of lines in labels, which are arranged from top to bottom in the number of 50 pieces. But when only the last line is updated, it is not necessary to update all labels, it is enough to update only one label which corresponds to this line. Turn on optimizeUpdate mode and we get more than a 2x performance gain.

I decided to test the display on labels in more detail, as this test period is too small for it, due to its speed. Therefore, I increased test period. And got the following results.

WithoutoptimizeUpdate: false

optimizeUpdate: false

WithoptimizeUpdate: true

optimizeUpdate: true

I have added all the results to Excel

comparizon-of-results

The first histogram shows the overall comparison, the second one only shows the variant with labels.

Conclusion: display created on CChartObjectLabel may be 83.7 times faster than the equivalent one on CCanvas. It is not for nothing that pixel operations are considered to be the most costly in all programs!

I am attaching a table with test results. Source code can be downloaded from KB:https://www.mql5.com/ru/code/33898


Files:
 

I don't understand why the comparison was in the Visualiser and not in the Terminal?

I haven't looked into the code. For such tasks Kanvas is made one for all "50 lines".


In the Terminal, I measured through the Usage-bibble. The methods show no significant difference.

 
fxsaber:

I don't understand why the comparison was in the Visualiser and not in the Terminal?

Because in the Visualiser it is the slow speed of Canvas that is causing the problems. And you can see what they are. Such a display eats up more than 50% of CPU time, I mentioned it above! And in Terminal you would have to call methods in a loop to see everything. But I didn't bother with that. I have an Expert Advisor running in the loop with offline optimization, where, in fact, I need such a display with fast updates. But I'm not ready to present it at the moment because the project is not yet complete.


fxsaber:

I haven't looked into the code. For such tasks Kanvas is made one for all "50 lines".

Then have a look. It's the only one there!

 
You're misleading people.
You really want to rub my nose in it, don't you?
I knew you'd want to do something like that. And I knew you'd make something like this up.

You don't know how to prepare comparison tests.

 
Mihail Matkovskij:

Because in the Visualiser, it's the slow speed of Canvas that's causing the problems. And you can see which ones. Such a display eats up more than 50% of CPU time, I mentioned it above! And in Terminal you would have to call methods in a loop to see everything. But I didn't bother with that. I have an Expert Advisor running in the loop with offline optimization, where, in fact, I need such a display with fast updates. But I'm not ready to present it at the moment, as the project is not yet complete.


Then take a look at it. It's the only one there!

Well... if you're only writing for a visualiser, then play these games alone. Haven't you ever heard that any graphics, even position opening/closing marks slow down the renderer? No.

I'll try not to disturb you... create separate labels for each letter... and also a separate resource...

 
Nikolai Semko:
You're misleading people.
You want to rub my nose in it, don't you?
I knew you'd want to do something like that. I knew you'd want to do something like this.

You don't know how to prepare comparison tests.

All I understood from your post were the words "delusion", "LOL", "I don't know how to prepare tests". Really, I don't understand how they relate to this topic... The rest, I don't understand from the word "at all"! When I created this thread, I wanted to seeconstructive criticism here, not a bunch of incomprehensible claims! So, bother to explain your words. Otherwise, don't write nonsense here!

 
Alexey Viktorov:

Well... if you only write for the visualiser, then play these games alone. Have you never heard that any graphics, even position opening/closing marks slow down the visualizer? No.

I'll try not to disturb you... create separate labels for each letter... and also a separate resource...

I hasten to inform you, Alexei. You, of course, tend to fantasize, as does Nikolai... But it's not really the way you imagine it to be. Simply, different solutions are needed for different tasks. Will you and Nikolai have any substantive comments?!

 
Mihail Matkovskij:

All I understood from your post were the words "delusion", "LOL", "I don't know how to prepare tests". Really, I don't understand how they relate to this topic... The rest, I don't understand from the word "at all"! When I created this thread, I wanted to seeconstructive criticism here, not a bunch of incomprehensible claims! So, bother to explain your words. Otherwise, don't write nonsense here!

Patience, my friend, patience.
I don't have as much time as you do. I'm in my last semester and have three group projects in parallel. So I'm here in impulse mode.
But, OK, I can convince you that you are deluded, just relax and don't strain so much. Otherwise my efforts will be in vain.
Unless, of course, your mind can subdue your emotions.
 
Nikolai Semko:
Patience my friend, patience.
I don't have as much time as you do. I'm in my last semester and I have three group projects in parallel. So I'm here on impulse.
But, OK, I can convince you of your delusion, just relax and don't work so hard. Otherwise my efforts will be in vain.

Go ahead. Only understand the codeproperly first, because the code is a complicated thing, and I need clearly substantiated claims!

 

I don't get it. The first image has a canvas and there is text on it.

The subsequent images do not have similar text on the graphic.

I mean, what was being compared then?

 
Mihail Matkovskij:

Go ahead. But first understand the codeproperly, because code is a complicated thing, and I need a clear argumentative claim!

I won't understand your code "properly". Because I've already looked into it. Short verdict - woe from mind.
Better you understand my code, which I will write in the next couple of months.