<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import collections <EOL> import subprocess <EOL> import sys <EOL> import os <EOL> PYPY = os . path . expanduser ( '<STR_LIT>' ) <EOL> SLP = os . path . expanduser ( '<STR_LIT>' ) <EOL> PY3 = os . path . expanduser ( '<STR_LIT>' ) <EOL> EXE_BACKEND_MATRIX = [ <EOL> [ PYPY , '<STR_LIT>' ] , <EOL> [ PYPY , '<STR_LIT>' ] , <EOL> [ SLP , '<STR_LIT>' ] , <EOL> [ SLP , '<STR_LIT>' ] , <EOL> [ PY3 , '<STR_LIT>' ] <EOL> ] <EOL> RST = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> COLUMN_WIDTHS = <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:16> , <NUM_LIT:7> <EOL> BenchmarkResult = collections . namedtuple ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:time>' ] ) <EOL> def stdout_to_results ( s ) : <EOL> """<STR_LIT>""" <EOL> results = s . strip ( ) . split ( '<STR_LIT:\n>' ) <EOL> return [ BenchmarkResult ( * r . split ( ) ) for r in results ] <EOL> def get_benchproc_results ( clargs , ** kwargs ) : <EOL> p = subprocess . Popen ( <EOL> clargs , stdout = subprocess . PIPE , stderr = subprocess . PIPE , ** kwargs ) <EOL> stdout , stderr = p . communicate ( ) <EOL> if p . returncode != <NUM_LIT:0> : <EOL> sys . stderr . write ( '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( clargs ) ) <EOL> sys . stderr . write ( stderr ) <EOL> return [ ] <EOL> results = stdout_to_results ( stdout ) <EOL> for br in results : <EOL> print ( justify_benchresult ( br ) ) <EOL> return results <EOL> def benchmark_process_and_backend ( exe , backend ) : <EOL> """<STR_LIT>""" <EOL> env = dict ( os . environ ) <EOL> env [ '<STR_LIT>' ] = backend <EOL> args = [ exe , '<STR_LIT>' , '<STR_LIT>' ] <EOL> return get_benchproc_results ( args , env = env ) <EOL> def benchmark_go ( ) : <EOL> """<STR_LIT>""" <EOL> subprocess . check_call ( [ '<STR_LIT>' , '<STR_LIT:version>' ] , stdout = subprocess . PIPE ) <EOL> return get_benchproc_results ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def collect_results ( ) : <EOL> """<STR_LIT>""" <EOL> results = [ ] <EOL> for exe , backendname in EXE_BACKEND_MATRIX : <EOL> results . extend ( benchmark_process_and_backend ( exe , backendname ) ) <EOL> results . extend ( benchmark_go ( ) ) <EOL> results . sort ( <EOL> key = lambda br : ( br . benchmark , float ( br . time ) , br . platform , br . backend ) ) <EOL> return results <EOL> def insert_seperator_results ( results ) : <EOL> """<STR_LIT>""" <EOL> sepbench = BenchmarkResult ( * [ '<STR_LIT:U+0020>' * w for w in COLUMN_WIDTHS ] ) <EOL> last_bm = None <EOL> for r in results : <EOL> if last_bm is None : <EOL> last_bm = r . benchmark <EOL> elif last_bm != r . benchmark : <EOL> yield sepbench <EOL> last_bm = r . benchmark <EOL> yield r <EOL> def justify_benchresult ( br ) : <EOL> middle = '<STR_LIT:|>' . join ( br [ i ] . ljust ( COLUMN_WIDTHS [ i ] ) for i in range ( len ( br ) ) ) <EOL> return '<STR_LIT>' % middle <EOL> def make_sepline ( char = '<STR_LIT:->' ) : <EOL> seperator_line = '<STR_LIT>' . format ( <EOL> * [ char * w for w in COLUMN_WIDTHS ] ) <EOL> return seperator_line <EOL> def main ( ) : <EOL> print ( '<STR_LIT>' ) <EOL> results = insert_seperator_results ( collect_results ( ) ) <EOL> with open ( RST , '<STR_LIT:w>' ) as f : <EOL> def w ( s ) : <EOL> f . write ( s ) <EOL> f . write ( '<STR_LIT:\n>' ) <EOL> f . flush ( ) <EOL> w ( '<STR_LIT>' ) <EOL> w ( '<STR_LIT>' ) <EOL> w ( make_sepline ( ) ) <EOL> w ( '<STR_LIT>' ) <EOL> w ( make_sepline ( '<STR_LIT:=>' ) ) <EOL> for br in results : <EOL> f . write ( '<STR_LIT:U+0020>' ) <EOL> f . write ( justify_benchresult ( br ) ) <EOL> f . write ( '<STR_LIT:\n>' ) <EOL> f . write ( make_sepline ( ) ) <EOL> f . write ( '<STR_LIT:\n>' ) <EOL> print ( '<STR_LIT>' % RST ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
