Skip to content

Instantly share code, notes, and snippets.

@DQNEO
Created December 24, 2015 14:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DQNEO/c7c68f8f6e06eb4cfa9e to your computer and use it in GitHub Desktop.
Save DQNEO/c7c68f8f6e06eb4cfa9e to your computer and use it in GitHub Desktop.
$(pwd) vs $PWD comparison
#!/bin/bash
for i in $(seq 1 10000)
do
echo $(pwd) >/dev/null
done
#!/bin/bash
for i in $(seq 1 10000)
do
echo $PWD >/dev/null
done
@DQNEO
Copy link
Author

DQNEO commented Dec 24, 2015

Benchmark results

$ time fork_pwd.sh
fork_pwd.sh  3.42s user 5.83s system 92% cpu 9.961 total

$ time var_pwd.sh
var_pwd.sh  0.15s user 0.07s system 98% cpu 0.222 total

@miy4mori
Copy link

miy4mori commented Jun 4, 2017

$PWD is a variable,$(pwd) will execute the command pwd.

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