git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 16/29] perf: add a performance comparison test of grep -G, -E and -P

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 13, 2017, 23:14 UTC
Message-ID
<20170513231509.7834-17-avarab@gmail.com>
In-Reply-To
<20170513231509.7834-1-avarab@gmail.com>

Add a very basic performance comparison test comparing the POSIX basic, extended and perl engines.

In theory the "basic" and "extended" engines should be implemented using the same underlying code with a slightly different pattern parser, but some implementations may not do this. Jump through some slight hoops to test both, which is worthwhile since "basic" is the default.

Running this on an i7 3.4GHz Linux 4.9.0-2 Debian testing against a checkout of linux.git & latest upstream PCRE, both PCRE and git compiled with -O3 using gcc 7.1.1:

    $ GIT_PERF_REPEAT_COUNT=10 GIT_PERF_LARGE_REPO=~/g/linux ./run p7820-grep-engines.sh
    [...]
    -------------------------------------------------------------
    7820.1: basic grep how.to                     0.28(1.27+0.41)
    7820.2: extended grep how.to                  0.29(1.23+0.44)
    7820.3: perl grep how.to                      0.27(1.14+0.47)
    7820.5: basic grep ^how to                    0.28(1.18+0.46)
    7820.6: extended grep ^how to                 0.28(1.25+0.40)
    7820.7: perl grep ^how to                     0.48(2.76+0.40)
    7820.9: basic grep [how] to                   0.42(2.20+0.42)
    7820.10: extended grep [how] to               0.41(2.12+0.50)
    7820.11: perl grep [how] to                   0.48(2.59+0.42)
    7820.13: basic grep \(e.t[^ ]*\|v.ry\) rare   0.55(3.26+0.44)
    7820.14: extended grep (e.t[^ ]*|v.ry) rare   0.54(3.34+0.38)
    7820.15: perl grep (e.t[^ ]*|v.ry) rare       0.88(5.82+0.35)
    7820.17: basic grep m\(ú\|u\)lt.b\(æ\|y\)te   0.29(1.26+0.48)
    7820.18: extended grep m(ú|u)lt.b(æ|y)te      0.29(1.36+0.39)
    7820.19: perl grep m(ú|u)lt.b(æ|y)te          0.32(1.61+0.43)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/perf/p7820-grep-engines.sh | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 t/perf/p7820-grep-engines.sh
diff --git a/t/perf/p7820-grep-engines.sh b/t/perf/p7820-grep-engines.sh
new file mode 100755
index 0000000000..eb439900f3
--- /dev/null
+++ b/t/perf/p7820-grep-engines.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+test_description="Comparison of git-grep's regex engines"
+
+. ./perf-lib.sh
+
+test_perf_large_repo
+test_checkout_worktree
+
+for pattern in \
+	'how.to' \
+	'^how to' \
+	'[how] to' \
+	'\(e.t[^ ]*\|v.ry\) rare' \
+	'm\(ú\|u\)lt.b\(æ\|y\)te'
+do
+	for engine in basic extended perl
+	do
+		if test $engine != "basic"
+		then
+			# Poor man's basic -> extended converter.
+			pattern=$(echo $pattern | sed 's/\\//g')
+		fi
+		test_perf "$engine grep $pattern" "
+			git -c grep.patternType=$engine grep -- '$pattern' >'out.$engine' || :
+		"
+	done
+
+	test_expect_success "assert that all engines found the same for $pattern" "
+		test_cmp 'out.basic' 'out.extended' &&
+		test_cmp 'out.basic' 'out.perl'
+	"
+done
+
+test_done
-- 
2.11.0
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 20 of 42 in “Easy to review grep & pre-PCRE changes”
  1. 00/29 Easy to review grep & pre-PCRE changesÆvar Arnfjörð Bjarmason, May 13, 2017
  2. 01/29 Makefile & configure: reword inaccurate comment about PCREÆvar Arnfjörð Bjarmason, May 13, 2017
  3. 02/29 grep & rev-list doc: stop promising libpcre for --perl-regexpÆvar Arnfjörð Bjarmason, May 13, 2017
  4. 04/29 log: add exhaustive tests for pattern style options & configÆvar Arnfjörð Bjarmason, May 13, 2017
  5. Junio C HamanoMay 15, 2017
  6. Ævar Arnfjörð BjarmasonMay 15, 2017
  7. Junio C HamanoMay 16, 2017
  8. 05/29 grep: add a test asserting that --perl-regexp dies when !PCREÆvar Arnfjörð Bjarmason, May 13, 2017
  9. 03/29 test-lib: rename the LIBPCRE prerequisite to PCREÆvar Arnfjörð Bjarmason, May 13, 2017
  10. 06/29 grep: add a test for backreferences in PCRE patternsÆvar Arnfjörð Bjarmason, May 13, 2017
  11. 07/29 grep: change non-ASCII -i test to stop using --debugÆvar Arnfjörð Bjarmason, May 13, 2017
  12. 08/29 grep: add tests for --threads=N and grep.threadsÆvar Arnfjörð Bjarmason, May 13, 2017
  13. 09/29 grep: amend submodule recursion test for regex engine testingÆvar Arnfjörð Bjarmason, May 13, 2017
  14. 10/29 grep: add tests for grep pattern types being passed to submodulesÆvar Arnfjörð Bjarmason, May 13, 2017
  15. 11/29 grep: add a test helper function for less verbose -f \0 testsÆvar Arnfjörð Bjarmason, May 13, 2017
  16. 12/29 grep: prepare for testing binary regexes containing rx metacharactersÆvar Arnfjörð Bjarmason, May 13, 2017
  17. 13/29 grep: add tests to fix blind spots with \0 patternsÆvar Arnfjörð Bjarmason, May 13, 2017
  18. 14/29 perf: add a GIT_PERF_MAKE_COMMAND for when *_MAKE_OPTS won't doÆvar Arnfjörð Bjarmason, May 13, 2017
  19. 15/29 perf: emit progress output when unpacking & buildingÆvar Arnfjörð Bjarmason, May 13, 2017
  20. 16/29 perf: add a performance comparison test of grep -G, -E and -PÆvar Arnfjörð Bjarmason, May 13, 2017
  21. 18/29 grep: catch a missing enum in switch statementÆvar Arnfjörð Bjarmason, May 13, 2017
  22. Junio C HamanoMay 15, 2017
  23. Ævar Arnfjörð BjarmasonMay 15, 2017
  24. 17/29 perf: add a performance comparison of fixed-string grepÆvar Arnfjörð Bjarmason, May 13, 2017
  25. 20/29 grep: remove redundant `regflags &= ~REG_EXTENDED` assignmentsÆvar Arnfjörð Bjarmason, May 13, 2017
  26. Junio C HamanoMay 15, 2017
  27. Ævar Arnfjörð BjarmasonMay 15, 2017
  28. 19/29 grep: remove redundant regflags assignment under PCREÆvar Arnfjörð Bjarmason, May 13, 2017
  29. 21/29 grep: factor test for \0 in grep patterns into a functionÆvar Arnfjörð Bjarmason, May 13, 2017
  30. Junio C HamanoMay 15, 2017
  31. Ævar Arnfjörð BjarmasonMay 15, 2017
  32. 22/29 grep: change the internal PCRE macro names to be PCRE1Ævar Arnfjörð Bjarmason, May 13, 2017
  33. 23/29 grep: change internal *pcre* variable & function names to be *pcre1*Ævar Arnfjörð Bjarmason, May 13, 2017
  34. 25/29 test-lib: add a PTHREADS prerequisiteÆvar Arnfjörð Bjarmason, May 13, 2017
  35. 26/29 pack-objects & index-pack: add test for --threads warningÆvar Arnfjörð Bjarmason, May 13, 2017
  36. 24/29 grep: move is_fixed() earlier to avoid forward declarationÆvar Arnfjörð Bjarmason, May 13, 2017
  37. 27/29 pack-objects: fix buggy warning about threadsÆvar Arnfjörð Bjarmason, May 13, 2017
  38. Junio C HamanoMay 15, 2017
  39. Ævar Arnfjörð BjarmasonMay 15, 2017
  40. 28/29 grep: given --threads with NO_PTHREADS=YesPlease, warnÆvar Arnfjörð Bjarmason, May 13, 2017
  41. 29/29 grep: assert that threading is enabled when calling grep_{lock,unlock}Ævar Arnfjörð Bjarmason, May 13, 2017
  42. Junio C HamanoMay 15, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.