emperor: (Default)
"time" is a reserved keyword in bash, not a builtin as one might naively expect[1,2]. Even more amusingly, many UN*X systems also have /usr/bin/time which has rather less nice output.

This leads to some irritating edge-cases if you forget this (or didn't realise it in the first place). Consider:

bash-3.2$ time sleep 1

real    0m1.009s
user    0m0.000s
sys     0m0.002s
bash-3.2$ FOO=bar time sleep 1
        1.00 real         0.00 user         0.00 sys
bash-3.2$ time FOO=bar sleep 1

real    0m1.002s
user    0m0.000s
sys     0m0.002s


...and things only get worse if you actually start chaining things together...

bash-3.2$ time sleep 1 | time sleep 4
        4.00 real         0.00 user         0.00 sys

real    0m4.004s
user    0m0.001s
sys     0m0.005s


Not perhaps the best design decision ever...

[1] #chiark thinks this was to make it possible to time entire pipelines, although there would be several obvious idioms for doing that if time were a builtin
[2] See the "Pipelines" section in bash(1) for more details

August

SunMonTueWedThuFriSat
          1
 
2
 
3
 
4
 
5
 
6
 
7
 
8
 
9
 
10 11
 
12
 
13
 
14
 
15
 
16
 
17
 
18
 
19
 
20
 
21
 
22
 
23
 
24
 
25
 
26
 
27
 
28
 
29
 
30
 
31