[PATCH] tests: quickly check if the glob line already matches the output

Simon Heimberg simohe at besonet.ch
Fri Feb 8 12:01:21 CST 2013


Am 08.02.2013 11:52, schrieb Bryan O'Sullivan:
> On Wed, Feb 6, 2013 at 9:59 PM, Simon Heimberg <simohe at besonet.ch 
> <mailto:simohe at besonet.ch>> wrote:
>
>     tests: quickly check if the glob line already matches the output
>
>
> Does this have any practical impact? 
Well, this one not because there is a bug. The comparison should be "el 
+ '\n' == l".
And with the corrected line not a big impact. We theoretically win 0.07 
milliseconds when running all tests.
I will resend the fixed patch with the next one for showing a real use.

Greetings,
Simon

================================
Calculations:
Comparing an equal line goes down from 178 to 1.6 micro seconds. In the 
entire test suite, there are 482 lines with a glob matching only "/". 
This is a maximum speed-up of 0.07 microseconds. (The slowdown from 153 
to 169 micro seconds for a normal match on 861 lines is considered.)

==========================================
python script for testing the run time of globalmatch, to run in the 
tests directory
==========================================
p = None # for pattern, make globally available

rt = __import__("run-tests")
gm = rt.globmatch

def t(n = 50000):
     """returns the mean time for matching, in us (micro seconds)

     returns the mean time for running the matching function,
     once for direct match, once for failed
     """
     r = []
     setup = 'from __main__ import gm, c, p'
     global p
     for p in [c.rstrip(), c.rstrip().replace('/', '?', 2)]:
         r.append(timeit.Timer('gm(p, c)', setup).timeit(number=n) / n * 
1000000)
     return r

c = "an/example/string/to/check\n"

if __name__ == "__main__":
     print t()

==========================================
shell line for couning glob lines with no * and ?
==========================================
grep -c "^[^\*\?]*(glob)" *.t | awk -F ":" 'BEGIN {S=0}
{printf("%03d %s\n", $2, $1); S=S+$2}
END {print "   =>", S}'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130208/f451790b/attachment.html>


More information about the Mercurial-devel mailing list