-2

I obtained the following:

$ time $(tee < infile > outfile)
real 0m14.721s
user 0m0.094s
sys 0m2.629s

$ time $(cat infile | tee > outfile)
real 0m8.931s
user 0m0.123s
sys 0m3.168

Is that difference just owing to redirection/piping, or is there something else going on here? Running them a second time gave the following:

$ time $(tee < infile > outfile)
real 0m11.558
user 0m0.113s
sys 0m2.691s

$ time $(cat infile | tee > outfile)
real 0m8.822s
user 0m0.120s
sys 0m3.125s

PS: Both infile and outfile were mp4 files, cached in ram; if that makes any difference.

Edit: I meant tee < infile > outfile and not tee < infile tee > outfile.

  • Note: no need for $() it will result in output being thrown away, and time does not need it. () would be good though. – ctrl-alt-delor Jul 28 '18 at 10:17
  • You just edited the commands, but leave the timings for the old commands. ☹ (-1) – ctrl-alt-delor Jul 28 '18 at 10:46
  • .. because that was the result I obtained ... I had made the mistake in the body. – digikar Jul 28 '18 at 11:00
  • I did not believe you so, I have just repeated the experiment. The one with cat is slower. I still don't believe you. – ctrl-alt-delor Jul 28 '18 at 11:20
  • Why do you time the result of executing the output of those commands? – Kusalananda Jul 28 '18 at 11:44
1

The examples are not the same as in the title.

For the question in the title.

The version with cat will be marginally slower.

For the question in the body

The first command, is writing two files. This is why is is slower. The second is starting an extra process (cat), but this is a small slowdown compared to writing extra file.

The second run is faster, probably, because the read is cached.

Explenation

tee < infile tee > outfile is functionally equivalent, but faster than cat infile | tee tee > outfile, where as tee > outfile is not. The first two produce two file, the 3rd produces one, so will be faster.

  • Look again tee > outfile it only has one output. – ctrl-alt-delor Jul 28 '18 at 10:16
  • Thanks for pointing out! Sorry, I had written it wrongly; but I checked my history - the title is what I meant. – digikar Jul 28 '18 at 10:26

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.