Skip to content

Commit 853bd0d

Browse files
pks-tgitster
authored andcommitted
t5401: speed up creation of many branches
One of the tests in t5401 creates a bunch of branches by calling git-branch(1) for every one of them. This is quite inefficient and takes a comparatively long time even on Unix systems where spawning processes is comparatively fast. Refactor it to instead use git-update-ref(1), which leads to an almost 10-fold speedup: ``` Benchmark 1: ./t5401-update-hooks.sh (rev = HEAD) Time (mean ± σ): 983.2 ms ± 97.6 ms [User: 328.8 ms, System: 679.2 ms] Range (min … max): 882.9 ms … 1078.0 ms 3 runs Benchmark 2: ./t5401-update-hooks.sh (rev = HEAD~) Time (mean ± σ): 9.312 s ± 0.398 s [User: 2.766 s, System: 6.617 s] Range (min … max): 8.885 s … 9.674 s 3 runs Summary ./t5401-update-hooks.sh (rev = HEAD) ran 9.47 ± 1.02 times faster than ./t5401-update-hooks.sh (rev = HEAD~) ``` Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4626269 commit 853bd0d

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

t/t5401-update-hooks.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ test_expect_success 'pre-receive hook that forgets to read its input' '
133133
EOF
134134
rm -f victim.git/hooks/update victim.git/hooks/post-update &&
135135
136-
for v in $(test_seq 100 999)
137-
do
138-
git branch branch_$v main || return
139-
done &&
136+
printf "create refs/heads/branch_%d main\n" $(test_seq 100 999) >input &&
137+
git update-ref --stdin <input &&
140138
git push ./victim.git "+refs/heads/*:refs/heads/*"
141139
'
142140

0 commit comments

Comments
 (0)