tapview is very slow

tapview is very slow, and can often be the slowest part of a testbench with many tests. For example,

$ time { echo 1..256; for i in `seq 1 256`; do echo ok $i; done } | tapview 
................................................................................................................................................................................................................................................................
256 tests, 0 failures.

real	0m4.579s
user	0m4.125s
sys	0m0.468s

and for comparison,

$ time { echo 1..256; for i in `seq 1 256`; do echo ok $i; done } > /dev/null

real	0m0.002s
user	0m0.001s
sys	0m0.001s

Some initial profiling reveals that most of the time is being spent in expr. I think a good course of action would be to replace expr with test wherever possible. There are also several places where regexes can be combined. For example,

if expr "$line" : ".* *SKIP" >/dev/null || expr "$line" : ".* *skip" >/dev/null

can be converted into

if expr "$line" : ".* *\(SKIP\|skip\)" >/dev/null

There are also several cases where we match unnecessarily. For example, we check for a plan line on every line of input, even after we've already processed a plan line. I think it would be more prudent to, if we've already seen a plan line, defer checking for plan lines until after we've tried to parse a test output line and failed.

Edited by Sean Anderson