git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Stefan Beller <sbeller@google.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Drastic jump in the time required for the test suite
Date: Thu, 20 Oct 2016 17:56:47 -0400	[thread overview]
Message-ID: <20161020215647.5no7effvutwep2xt@sigill.intra.peff.net> (raw)
In-Reply-To: <20161020213803.7d7bymby7pouzij3@sigill.intra.peff.net>

On Thu, Oct 20, 2016 at 05:38:03PM -0400, Jeff King wrote:

> I think that helper still ends up using "cat" and "diff" under the hood,
> unless you write those bits in pure shell. But at that point, I suspect
> we could "cat" and "test_cmp" in pure shell, something like:
> [...]
> Those are both completely untested. But maybe they are worth playing
> around with for somebody on Windows to see if they make a dent in the
> test runtime.

If you tried to run them, you probably noticed that the "untested" was
really true. One of the functions was missing an "else", and the other
forgot to add a "\n" to its printf.

The patch below gets closer, though there are still a handful of test
failures.  I didn't investigate deeply, but I think at least one is
related to the "read/printf" version of cat not being binary-clean.

-Peff

---
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index fdaeb3a96b..de37f3d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -685,9 +685,48 @@ test_expect_code () {
 # - not all diff versions understand "-u"
 
 test_cmp() {
+	# optimize for common "they are the same" case
+	# without any subshells or subprograms
+	while true; do
+		if ! read -r line1 <&3
+		then
+			if ! read -r line2 <&4
+			then
+				# EOF on both; good
+				return 0
+			else
+				# EOF only on file1; fail
+				break
+			fi
+		fi
+		if ! read -r line2 <&4
+		then
+			# EOF only on file2; fail
+			break
+		fi
+		test "$line1" = "$line2" || break
+	done 3<"$1" 4<"$2"
+
+	# if we get here, the optimized version found some
+	# difference. We can just "return 1", but let's run
+	# the real $GIT_TEST_CMP to provide pretty output.
+	# This should generally only happen on test failures,
+	# so performance isn't a big deal.
 	$GIT_TEST_CMP "$@"
 }
 
+cat () {
+	# optimize common here-doc usage
+	if test $# -eq 0
+	then
+		while read -r line
+		do
+			printf '%s\n' "$line"
+		done
+	fi
+	command cat "$@"
+}
+
 # test_cmp_bin - helper to compare binary files
 
 test_cmp_bin() {

  parent reply	other threads:[~2016-10-20 21:56 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-19  9:18 Drastic jump in the time required for the test suite Johannes Schindelin
2016-10-19 17:32 ` Junio C Hamano
2016-10-19 20:56   ` Jeff King
2016-10-20 10:50     ` Johannes Schindelin
2016-10-20 11:39       ` Jeff King
2016-10-20 19:54       ` Stefan Beller
2016-10-20 21:38         ` Jeff King
2016-10-20 21:53           ` Stefan Beller
2016-10-20 21:57             ` Jeff King
2016-10-20 21:56           ` Jeff King [this message]
2016-10-21  5:27           ` Johannes Sixt
2016-10-21  8:24             ` Jeff King
2016-10-20 10:17   ` Johannes Schindelin
2016-10-20 12:31     ` Jeff King
2016-10-20 16:30       ` Stefan Beller
2016-10-20 21:00         ` Jeff King
2016-10-20 23:20           ` Jeff King
2016-10-20 20:38       ` Johannes Sixt
2016-10-20 21:03         ` Jeff King
2016-10-20 20:40       ` Dennis Kaarsemaker
2016-10-21 11:03         ` Duy Nguyen
2016-10-20 16:16     ` Junio C Hamano
2016-10-20 17:13       ` Matthieu Moy
2016-10-20 11:02 ` Duy Nguyen
2016-10-20 16:40   ` René Scharfe
2016-10-21 10:59     ` Duy Nguyen
2016-10-21 20:28       ` René Scharfe
2016-10-21 13:10     ` Matthieu Moy
2016-10-21 19:57       ` René Scharfe
2016-10-27 20:41 ` Eric Wong
2016-10-28  6:38   ` Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161020215647.5no7effvutwep2xt@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).