performance - Named pipe faster than normal pipe in bash? -
i'm writing bash script in i'm using lot of named pipes. thought might create bit of overhead compared using pipes directly, decided i'm okay that, wanted stats find out how i'm dealing with. therefore ran these 2 commands 50 times each, writing down times average:
time seq 1000000 | sort | head; time seq 1000000 | cat >a | cat | sort | head; #a created mkfifo
this not actual way i'll using named pipes
to write down times, used command:
for in `seq 50`; { time seq 1000000 | sort | head; } 2>&1 | grep real | cut -c8-12 >> normal_pipe; done
to astonishment, discovered these results:
normal pipe:
average: 1.712 sec
stddev: 0.0157 sec
unnamed pipe:
average: 1.644 sec
stddev: 0.0339 sec
my questions now:
- why named pipe faster?
- is benchmarking setup flawed?
- or difference due other processes running in background?
i'm guessing that, since sort
can start working once has input (right?), how pipe spits out eof...
i ran same tests few times on machine , results showed little difference between 2 styles of piping. hunch difference of .068 seconds nothing special , due background tasks, said.
Comments
Post a Comment