2

I was executing a script and by measuring the time that he made, i've found that using the -v on some mv commands made it much slower,(all the outputs are redirected to a file) .

So why is the -v (verbose mode) make the execution of a command makes it slower, for example:

mv file.txt newname.txt faster then mv -v file.txt newname.txt when dealing with millions of files ?

  • You can test for yourself by prepending the command to test with time. – Murphy Oct 17 '17 at 11:17
  • i've done and the difference is about 30% , i've edited my question. – Kingofkech Oct 17 '17 at 11:18
  • 1
    yes. commands are single threaded and spend additional time in tty input/output. not sure about mv, but untaring a huge archive over a slow ssh session is significantly slow – myaut Oct 17 '17 at 11:18
  • Capture the output of such a millions of files move and then time how much it takes to just cat that text (ok, or just fake such a mof-move-log file). Maybe trying different terminals will give more insight... will a real text mode terminal be faster compared to move megabytes of to 32bit per pixel rendered text? Lots of research! Game, fun and excitement for the whole family! o;-) – yeti Oct 17 '17 at 11:42
  • For large directories like this caching plays a big role. Basically a second (and subsequent) run of mv will be faster than the first, regardless of which has the -v option. – Satō Katsura Oct 17 '17 at 11:54
3

When a program runs each time it prints to the file it must communicate with the kernel using IPC. Redirection necessitates this and then the file system must actually write the changes which are buffered. This breaks up the scheduling of the programs run time and must wait a comparatively long time to buffer then simply doing what ever it was doing most of which probably was not IO locked. This is of course only a very general phenomenon and would apply wildly differently from command to command. However it should be true that commands that would be IO locked anyway should be less likely to be that different when executed with verbose flags.

2

Because being verbose means doing more. And doing more takes longer than doing less.

  • I'd actually beg to differ on your second statement. For example you can "do less" by traversing an array for a search but it takes a lot less time if you "do more" by first making a hashtable. – jdwolf Oct 17 '17 at 13:28

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.