What is the fastest way to print out to a terminal?

Viewed 380

The question is pretty straight-forward, what is the fastest way to print out a string to the terminal?

I am making an "ASCII graphics engine" in C++, particularly on Linux, and i have noticed that printing with some big resolutions can be pretty slow.

Now, of course, its pretty fast, but still.

I want to find out whats the absolute fastest. Some things i have tried are just printing with cout, then i realized that was slow.

Then i printed with printf which was a huge difference.

I tried getting something faster by just using fwrite with stdout, but it didnt really make any noticeable difference.

I know it also depends on the terminal emulator, but im looking for whats the fastest way to do it in code.

I have noticed that Windows terminals are pretty fast, you can just directly write to the terminal buffer with the terminals, instead of printing to stdout.

Is there anything similiar to this on Linux?

2 Answers

Hey This might help you

you can use echo "" to print this is the fastest way to print on terminal

Well, echo “text” is the fastest way. The other fastest method is std::cout, it’s much faster than printf because it doesn’t parse text at runtime. cout is slower because it syncs to stdio, add std::ios_base::sync_with_stdio(false) to your main function to make cout faster

Related