Skip to content

Instantly share code, notes, and snippets.

@corneliusroemer
Last active March 10, 2023 09:19
Show Gist options
  • Save corneliusroemer/c1d9a7dddfed2849f71dae681c321e74 to your computer and use it in GitHub Desktop.
Save corneliusroemer/c1d9a7dddfed2849f71dae681c321e74 to your computer and use it in GitHub Desktop.
Bash subprocess spawn latency

Latency to start a subprocess in bash

Q: How long does it roughly take to spawn a subprocess in bash? A: Around 1 millisecond

Method

$ time for i in {0..1000} ; do $(echo "1") 2&>1 >/dev/null; done

real    0m0.890s
user    0m0.118s
sys     0m0.760s
$ time for i in {0..1000} ; do echo "1" 2&>1 >/dev/null; done

real    0m0.043s
user    0m0.015s
sys     0m0.028s

Comments/Contributions welcome

The answer on my system (M1 Pro, macOS 13.2, bash 5.2) seems to be around 0.85ms per subprocess.

I'd be curious what people find on different systems! Just run this and paste your output, mentioning your machine, OS and bash version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment