From 72ec2b37468d7f1f0c15e6b201f914802d9d3b4f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 4 Dec 2020 10:06:49 -0800 Subject: tr: fix pathological flushing. The AOSP build doesn't use tr (or anything that's still in pending), but the kernel folks have been more aggressive. They found that tr's pathological flushing was adding minutes to their build times. Just removing the fflush() made tr significantly faster for my trivial test, but still slow, with all the time going into stdio. Rewriting the loop to modify toybuf in place and then do one write per read made most of the difference, but special-casing the "neither -d nor -s" case made a measurable difference too on a Xeon. Bug: http://b/174773617 --- tests/tr.test | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 tests/tr.test (limited to 'tests') diff --git a/tests/tr.test b/tests/tr.test new file mode 100755 index 00000000..bb00a3ff --- /dev/null +++ b/tests/tr.test @@ -0,0 +1,11 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "" "tr 1 2" "223223223" "" "123123123" +testing "-d" "tr -d 1" "232323" "" "123123123" +testing "-s" "tr -s 1" "12223331222333" "" "111222333111222333" + +testing "no pathological flushing" "seq 10000000 | tr 1 2 > /dev/null" "" "" "" -- cgit v1.2.3