Tested against the WebKit git repo by entering the repo with 1 file dirty.
git diff --quiet --ignore-submodules HEAD
# Will tell if there are any uncomitted changes, staged or not.
0.6 sec
git diff-index --quiet HEAD
# Only tracked
2 sec
git diff --shortstat
8.2 sec
git status --porcelain
42 sec
zstyle ':vcs_info:*' check-for-changes true
50 sec
Unless you want to take untracked files into account too. The best I've come up with is:
This is the benchmark I got in a NFS filesystem with the WebKit repo clean:
git ls-files --other --exclude-standard
(lists untracked files)git status --porcelain
(lists indexed, unindexed and untracked files)git diff-index --no-ext-diff --quiet --cached HEAD
(checks indexed files)git diff-files --no-ext-diff --quiet
(checks unindexed files)