0

I'm running Mint 19 with cinnamon, but i think its a general question for any linux desktop environment. I have a python CLI application which has a lot of terminal output, so much, that the print statements rendering in the terminal window is actually slowing down the application. A lame question: does the speed improve, if the terminal is minimized (the rendering is unneccessary and perhaps ommited)?

  • Could you share some more concrete details? How much data is produced by the application, how quickly? How do you know that the terminal is slowing it down? Which terminal emulator? – egmont Jan 8 at 21:58
2

If you want performance gain, consider running your commands with:

mycommand &>/dev/null

or

mycommand &>~/mycommand.log 

And this other way are good too:

nohup mycommand

Note: This & is not to put the app in background but to redirect standard output and standard error.

Some benchmarks:

time hexdump HURRICANE\ SMITH\ -\ DON\ T\ LET\ IT\ DIE.mp3
real    0m17,525s

time hexdump HURRICANE\ SMITH\ -\ DON\ T\ LET\ IT\ DIE.mp3  &>/dev/null
real    0m0,226s

time hexdump HURRICANE\ SMITH\ -\ DON\ T\ LET\ IT\ DIE.mp3  &>/tmp/result.txt
real    0m0,244s

time nohup hexdump HURRICANE\ SMITH\ -\ DON\ T\ LET\ IT\ DIE.mp3  
real    0m0,251s

How terminal output can affect performance in real world?

For example... inside a Shell Script... !

#!/bin/bash
date >/tmp/start.txt
hexdump HURRICANE\ SMITH\ -\ DON\ T\ LET\ IT\ DIE.mp3 
date >/tmp/theend.txt 

Results :

cat /tmp/start.txt 
qua jan  9 14:49:08 -02 2019
cat /tmp/theend.txt
qua jan  9 14:49:25 -02 2019

As you see at this first example, the interpreter waited for all the output before going to the next command - this can be bad in a lot of situations.

Again now WITHOUT writing data directly to the terminal...

#!/bin/bash
date >/tmp/start.txt
hexdump HURRICANE\ SMITH\ -\ DON\ T\ LET\ IT\ DIE.mp3 >/tmp/results.txt 
date >/tmp/theend.txt 

Results :

cat /tmp/start.txt
qua jan  9 14:52:02 -02 2019
cat /tmp/theend.txt
qua jan  9 14:52:02 -02 2019

In the second example, the script runned fast and all the output data are ready in /tmp/result.txt for you.

If you just minimize the window, the performance gain will be almost nothing, because the app is still writing the log to the minimized terminal, so you can see then when you restore the window.

If you want to read what the comamnd is returning, without affecting its performance and without creating log files, try this other way:

yourcommand | less
  • Interesting remarks. I'll try and test my original proposition, just to see if theres a performance gain if terminal is minimized. Just thought someone tried this before. – U2ros Jan 8 at 19:26
1

It's unlikely that you'll get significant (or even noticeable) improvement by minimizing the terminal emulator.

One component of graphical terminal emulators is responsible for reading and handling the input, as quickly as they can do. For example, my preferred terminal emulator on my computer can read, parse and handle approximately 10 MB/s (it depends on the kind of data, of course).

Terminal emulators don't update their screen as soon as they handled some input, it would be unbearably slow. (This is what the Linux console does, and with framebuffer it is indeed unbearably slow, but becomes blazingly fast as soon as you switch to another VT.) Instead, graphical terminal emulators update their display several (maybe 20–60) times per second. They should all implement an adaptive framerate, that is, make sure they don't spend too much time painting. If painting is slow for whatever reason (e.g. giant terminal window, non-accelerated video card), they paint less frequently to make sure they can still devote plenty of CPU to reading the stream.

Under normal circumstances, the cost of repainting the screen a few dozen times per second should be quite small relative to the cost of reading and parsing as much data as they can, plus the cost of your application emitting them.

If your app's performance is really slowed down, it's probably not because of the terminal emulator rendering the contents slowly, it's probably because of the tty line through the kernel as well as terminal emulator processing the data slowly, which they have to do even when minimized.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.