I imagine time A | B would only measure the time taken to run A (since the argument to time is A). What's the solution ?
Depends on the shell. e.g. Bash has a keyword
time that times the whole pipeline. An external implementation of
time would only time
A in your example. A workaround might be to explicitly run an extra shell:
time sh -c "A | B"