cpp-terminal icon indicating copy to clipboard operation
cpp-terminal copied to clipboard

Test windows performances

Open flagarde opened this issue 2 years ago • 10 comments

@MCWertGaming You mentioned last time the Microsoft Windows terminal was quite slow.. Could you provide some code showing this ? I found some windows api to write to console... maybe it would be faster but this need some tests.

flagarde avatar Dec 12 '22 04:12 flagarde

That the terminal is pretty slow compared to linux can be seen in https://github.com/MCWertGaming/Furdevs-Chess. It's a small program I did in two weeks for a game jam. The drawing performance is pretty poor - while I draw the whole frame every time, which isn't ideal but I had to less time for optimizing that.

What I personally need is a renderer which is capable of updating the screen without the flashing you'll notice in my program on windows.

MCWertGaming avatar Dec 17 '22 18:12 MCWertGaming

ok thank I will try with the windows API for terminal and see if there is improvements

flagarde avatar Dec 17 '22 19:12 flagarde

We can improve std::cout performance by optionally disabling the printf compatibility. I think that this plus an efficient rendering algorythm in the window class would do the trick.

MCWertGaming avatar Dec 18 '22 20:12 MCWertGaming

I have some more time now and think that I'll make a Fork to implement #213 and look into finding a way to make real time applications / rendering usable on windows as well. I'll contribute it into cpp-terminal then when it's working ^^

MCWertGaming avatar Jan 01 '23 15:01 MCWertGaming

It seems the cout is not buffered on windows or some strange thing like this.. i found some function to turn it on but i didn't check the performance.. would be nice to have a special test for this... A very difficult screen to fill with many colors etc to have some benchmark

flagarde avatar Jan 01 '23 15:01 flagarde

std::cout in MSVC is slow (https://web.archive.org/web/20170329163751/https://connect.microsoft.com/VisualStudio/feedback/details/642876/std-wcout-is-ten-times-slower-than-wprintf-performance-bug-in-c-library).

"It is an unfortunate consequence of how our C and C++ Standard Library implementations are designed. The problem is that when printing to the console (instead of, say, being redirected to a file), neither our C nor C++ I/O are buffered by default. This is sometimes concealed by the fact that C I/O functions like printf() and puts() temporarily enable buffering while doing their work"

Microsoft suggests this fix (to enable buffering on cout/stdout):

setvbuf(stdout, 0, _IOLBF, 4096)

flagarde avatar Jan 01 '23 16:01 flagarde

Oh, seems nice! I'll make a small animation of some sort as example for this.

MCWertGaming avatar Jan 01 '23 18:01 MCWertGaming

I mean just rendering performance is not the only thing I need, some kind of centering of the content and resizing would be a nice addition, but I'm not yet sure how to implement something like that in a universal renderer. But having a constant rendering performance and some simple interface for interacting with a rendering buffer (the Window class) would be a nice start!

MCWertGaming avatar Jan 01 '23 18:01 MCWertGaming

@MCWertGaming Yes, it's just the start of the story but if this can improve some performance it would be great to add it.

flagarde avatar Jan 01 '23 18:01 flagarde

Of course, we'll implement it

MCWertGaming avatar Jan 15 '23 10:01 MCWertGaming