Re: [PATCH 2/2] for-each-ref: add --count-matches option

From
Derrick Stolee <hidden>
Date
2023-07-10 16:51:32
Reply to
Jeff King, 2023-06-27
On 6/27/2023 1:30 AM, Jeff King wrote:
On Mon, Jun 26, 2023 at 03:09:57PM +0000, Derrick Stolee via GitGitGadget wrote:
quoted
+for pattern in "refs/heads/" "refs/tags/" "refs/remotes"
+do
+   test_perf "count $pattern: git for-each-ref | wc -l" "
+       git for-each-ref $pattern | wc -l
+   "
+
+   test_perf "count $pattern: git for-each-ref --count-match" "
+       git for-each-ref --count-matches $pattern
+   "
+done
I don't think this is a very realistic perf test, because for-each-ref
is doing a bunch of work to generate its default format, only to have
"wc" throw most of it away. Doing:

 git for-each-ref --format='%(refname)' | wc -l

is much better (obviously you have to remember to do that if you care
about optimizing your command, but that's true of --count-matches, too).
Thank you for pointing this out! I'll be sure to modify the test and the
analysis about it.
The other check I need to compare is when multiple refspecs are provided
at the same time, which I do believe still is a valuable thing to combine
into a single process instead of multiple pipes to 'wc'.
Did you have any thoughts on whether or not this works as an option in
'git for-each-ref' or would be better broken into a new builtin?
Thanks,
-Stolee
Thread (8 messages) 8 messages, 5 authors, last reply 2023-07-11
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help