• Kirill Smelkov's avatar
    py.bench: New command to benchmark python code similarly to `go test -bench` · 9bf03d9c
    Kirill Smelkov authored
    + corresponding bits in golang.testing package.
    
    py.bench description follows:
    
    """
    py.bench, similarly to py.test, discovers bench_* functions and Bench* classes
    and then runs each discovered benchmark via golang.testing.benchmark. Similarly
    to `go test -bench`, benchmarking results are printed in Go benchmark format.
    
    For example, running py.bench on the following code::
    
        def bench_add(b):
            x, y = 1, 2
            for i in xrange(b.N):
                x + y
    
    gives something like::
    
        $ py.bench --count=3 x.py
        ...
        pymod: bench_add.py
        Benchmarkadd    50000000        0.020 µs/op
        Benchmarkadd    50000000        0.020 µs/op
        Benchmarkadd    50000000        0.020 µs/op
    """
    
    The implementation is based on t/py.bench from Wendelin.core - see
    following commits for its history:
    
    lab.nexedi.com/nexedi/wendelin.core/commit/51f252d4
    lab.nexedi.com/nexedi/wendelin.core/commit/074ce24d
    lab.nexedi.com/nexedi/wendelin.core/commit/ed13c3f9
    lab.nexedi.com/nexedi/wendelin.core/commit/fc08766d
    lab.nexedi.com/nexedi/wendelin.core/commit/5a1ed45a
    lab.nexedi.com/nexedi/wendelin.core/commit/bcab1246
    9bf03d9c
testing.py 3.26 KB