This week’s Question of the Week comes from MaxMaxie, and is about command line usage in Linux:
I’ve found myself using the
-vflag for lots of applications less and less (especially for trivial stuff like
cp). However, when I did and I was, say, unzipping a large file, it would take longer than when I didn’t use the
-vflag. I assume this is because the terminal has to process the text and I’m filling up whatever buffer it might have. But my question is, does this make the application actually run slower or does it complete in the same amount of time and what I’m seeing is the terminal trying to catch up?
According to Matt Jenkins, it does indeed. His explanation of why is an interesting read, but the question remains: exactly how much does it slow things down? I decided to find out – read on to see just how much of a difference verbose flags can make.
I wanted to test this on something with a mix of file sizes, so I chose the latest download of WordPress, unzipped it, and performed verbose and normal copy operations on the extracted file in Windows 7 and Ubuntu 11.04. The results confirmed what Matt Jenkins told us for Linux, but Windows shows a different story.
The xcopy command is used on Windows for copying directories of data. There is no timer command built into the Windows command prompt, so I made a rudimentary one which echos the time when the command starts to run and the time when the command is done running. Below are the times for copying with the default option, which is verbose, and the /Q switch, which runs the copy silently:
Interestingly, the speed was not always consistent: 2/3 times I ran it, the command was slower when using the default verbose options than it was when running with the quiet output flag. This may have to do with the program being designed to run with the extra info: it may take more processing time to generate that output, and then not show it, than it does to generate and show it.
The results for Linux are much more noticeable: the verbose command (with the -v flag) is slower every time, sometimes by as much as 75%.
It appears that running Linux commands in verbose mode does have a significant affect on the speed of the execution. In Windows, the difference is less well-defined. These were just some quick tests, and more benchmarks would be necessary to figure out how much of a difference occurs in what situations, but it seems like at least for Linux, the basic advice is true: in the future, if you’re looking for speed and don’t need that extra info, leave off that -v, and you might get done a bit quicker!