summaryrefslogtreecommitdiff
path: root/contrib/completion
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder@ira.uka.de>2013-06-24 00:28:02 (GMT)
committerSZEDER Gábor <szeder@ira.uka.de>2013-06-24 16:03:37 (GMT)
commita694258457e51f20e92854075914c8d3a4593367 (patch)
tree3ba4e86b6b771f0f482f9f899977796183c4c606 /contrib/completion
parent69a8141a5d81925b7e08cb228535e9ea4a7a02e3 (diff)
downloadgit-a694258457e51f20e92854075914c8d3a4593367.zip
git-a694258457e51f20e92854075914c8d3a4593367.tar.gz
git-a694258457e51f20e92854075914c8d3a4593367.tar.bz2
bash prompt: mention that PROMPT_COMMAND mode is faster
__git_ps1() is usually added to the prompt inside a command substitution, imposing the overhead of fork()ing a subshell. Using __git_ps1() for $PROMPT_COMMAND is slightly faster, because it avoids that command substitution. Mention this in the comments about setting up the git prompt. The whole series speeds up the bash prompt on Windows/MSysGit considerably. Here are some timing results in three scenarios, each repeated 10 times: At the top of the work tree, before: $ time for i in {0..9} ; do prompt="$(__git_ps1)" ; done real 0m1.716s user 0m0.301s sys 0m0.772s After: real 0m0.687s user 0m0.075s sys 0m0.396s After, from $PROMPT_COMMAND: $ time for i in {0..9} ; do __git_ps1 '\h:\w' '$ ' ; done real 0m0.546s user 0m0.075s sys 0m0.181s At the top of the work tree, detached head, before: real 0m2.574s user 0m0.376s sys 0m1.207s After: real 0m1.139s user 0m0.151s sys 0m0.500s After, from $PROMPT_COMMAND: real 0m1.030s user 0m0.245s sys 0m0.336s In a subdirectory, during rebase, stash status indicator enabled, before: real 0m3.557s user 0m0.495s sys 0m1.767s After: real 0m0.717s user 0m0.120s sys 0m0.300s After, from $PROMPT_COMMAND: real 0m0.577s user 0m0.047s sys 0m0.258s On Linux the speedup ratio is comparable to Windows, but overall it was about an order of magnitude faster to begin with. The last case from above, repeated 100 times, before: $ time for i in {0..99} ; do prompt="$(__git_ps1)" ; done real 0m2.806s user 0m0.180s sys 0m0.264s After: real 0m0.857s user 0m0.020s sys 0m0.028s Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Diffstat (limited to 'contrib/completion')
-rw-r--r--contrib/completion/git-prompt.sh10
1 files changed, 5 insertions, 5 deletions
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 7152ae4..daed6a1 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -15,11 +15,11 @@
# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
# the optional argument will be used as format string.
-# 3b) Alternatively, if you are using bash, __git_ps1 can be
-# used for PROMPT_COMMAND with two parameters, <pre> and
-# <post>, which are strings you would put in $PS1 before
-# and after the status string generated by the git-prompt
-# machinery. e.g.
+# 3b) Alternatively, for a slighly faster prompt, if you are
+# using bash, __git_ps1 can be used for PROMPT_COMMAND
+# with two parameters, <pre> and <post>, which are strings
+# you would put in $PS1 before and after the status string
+# generated by the git-prompt machinery. e.g.
# Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
# ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
# will show username, at-sign, host, colon, cwd, then