|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81377 - sandbox/variadic_templates/sandbox/slim/test
From: cppljevans_at_[hidden]
Date: 2012-11-16 19:28:56
Author: cppljevans
Date: 2012-11-16 19:28:55 EST (Fri, 16 Nov 2012)
New Revision: 81377
URL: http://svn.boost.org/trac/boost/changeset/81377
Log:
.py files used by or process output from *_run.py file.
Added:
sandbox/variadic_templates/sandbox/slim/test/compiler_guage.py (contents, props changed)
sandbox/variadic_templates/sandbox/slim/test/compiler_map.py (contents, props changed)
sandbox/variadic_templates/sandbox/slim/test/print_domain_range.py (contents, props changed)
sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_parserange.py (contents, props changed)
sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_plot.py (contents, props changed)
sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_tags.py (contents, props changed)
Added: sandbox/variadic_templates/sandbox/slim/test/compiler_guage.py
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/compiler_guage.py 2012-11-16 19:28:55 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,74 @@
+"""
+Classes for measuring the performance of a compiler
+"""
+import abc
+import subprocess
+
+class guage_abstract:
+ """
+ Abstract class for measuring compiler performance.
+ """
+ __metaclass__=abc.ABCMeta
+
+ @abc.abstractmethod
+ def names():
+ """
+ Names of performances measured by method, measure.
+ """
+ pass
+
+ @abc.abstractmethod
+ def measure(self,compiler_exe, compiler_args, measure_out):
+ """
+ Measure the performance of
+ compiler, compiler_exe,
+ with args, compiler_args,
+ while appending the measurements on file, measure_out.
+ """
+ pass
+
+class guage_time(guage_abstract):
+ """
+ Concrete class using system time function for measuring performance.
+ """
+
+ def names():
+ return ["user","system","elapsed"]
+
+ def measure(self, compiler_exe, compiler_args, measure_out):
+ compile_cmd=compiler_exe+compiler_args
+ time_format='"user:%U system:%S elapsed:%e"'
+ measure_cmd='time --format '+time_format+' '+compile_cmd
+ print(":measure_cmd=",measure_cmd)
+ if True:
+ rc=subprocess.call(
+ measure_cmd
+ , shell=True
+ , stdout=measure_out
+ , stderr=subprocess.STDOUT
+ )
+ print(":rc=",rc)
+ return rc
+ return 0
+
+class guage_ftime(guage_abstract):
+ """
+ Concrete class using -ftime-report compiler flag for measuring performance.
+ """
+
+ def names():
+ return []
+
+ def measure(self, compiler_exe, compiler_args, measure_out):
+ measure_cmd=compiler_exe+" -ftime-report "+compiler_args
+ print(":measure_cmd=",measure_cmd)
+ if True:
+ rc=subprocess.call(
+ measure_cmd
+ , shell=True
+ , stdout=measure_out
+ , stderr=subprocess.STDOUT
+ )
+ print(":rc=",rc)
+ return rc
+ return 0
Added: sandbox/variadic_templates/sandbox/slim/test/compiler_map.py
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/compiler_map.py 2012-11-16 19:28:55 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,19 @@
+"""
+ Provide map from compiler short name to
+ a tuple of:
+ 1) compiler location in file system
+ 2) compiler options
+"""
+
+COMPILER_MAP={}
+
+if True:
+ COMPILER_MAP["gcc4_8"]=(
+ "/home/evansl/download/gcc/4.8-20121028/install/bin/g++"
+ , "-std=gnu++11"
+ )
+if True:
+ COMPILER_MAP["clangxx"]=(
+ "/home/evansl/download/llvm/svn/build/Release/bin/clang"
+ , "-std=c++11 -cxx-isystem /home/evansl/download/llvm/svn/llvm/projects/libcxx/include"
+ )
Added: sandbox/variadic_templates/sandbox/slim/test/print_domain_range.py
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/print_domain_range.py 2012-11-16 19:28:55 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,19 @@
+"""
+print list((list(domain),list(range)) to stdout.
+"""
+from __future__ import print_function
+
+def print_domain_range(domain_range):
+ for domain_vals,range_vals in domain_range:
+ print(":domain_values_lst=",domain_vals)
+ #The reason for not using print("...",range_vals) instead
+ #of the following is that the float values printed have
+ #many decimal places. For some strange reason, printing
+ #each with separate print function call avoids that.
+ print(":range_values_lst= [",end="")
+ i=0
+ for val in range_vals:
+ if i > 0: print(", ",end="")
+ i+=1
+ print(val,end="")
+ print("]")
Added: sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_parserange.py
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_parserange.py 2012-11-16 19:28:55 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+##Purpose:
+## Parse the range output in the file produced by
+## tuple_benchmark_run.py
+##===============================================
+from __future__ import print_function
+import sys, re, pickle
+from tuple_benchmark_tags import TAG_TUPLE
+from print_domain_range import print_domain_range
+
+debug_print=0
+
+import abc
+
+class parse_range_abstract:
+ """
+ Abstract class for parsing output from compiler performance measurement.
+ """
+ __metaclass__=abc.ABCMeta
+
+ @abc.abstractmethod
+ def parse(range_str):
+ """
+ range_str is a string output from compiler performance measurement.
+ This method turns that into a list or range values
+ which are then returned.
+ """
+ pass
+
+class parse_range_time:
+ """
+ Concrete for parsing output from compiler performance measurement
+ made with system time command.
+ """
+
+ def __init__(self):
+ self.range_names=['user','system','elapsed']
+ range_values_pat\
+ ="^"\
+ +self.range_names[0]\
+ +":(.*) "\
+ +self.range_names[1]\
+ +":(.*) "\
+ +self.range_names[2]\
+ +":(.*)$"
+ self.range_values_re=re.compile(range_values_pat)
+
+ def names(self):
+ return self.range_names
+
+ def parse(self,range_values_str):
+ found=self.range_values_re.search(range_values_str)
+ range_values_lst=[]
+ n=len(self.range_names)
+ for i in range(1,1+n):
+ range_val=float(found.group(i))
+ range_values_lst.append(range_val)
+ return range_values_lst
+
+def main(argv):
+ result = None
+ if len(argv)>1:
+ run_file_inp=open(argv[1],mode='r')
+ else:
+ print("***expected input filename as argv[1]")
+ return 1
+ line_count=0
+ end_compilers=re.compile("^]"+TAG_TUPLE.compilers+"$")
+ for line_str in run_file_inp:
+ line_count+=1
+ found=end_compilers.search(line_str)
+ if debug_print:
+ print(":line=",line_str,end="")
+ print(":found=",found)
+ if found:
+ break
+ line_str=run_file_inp.next()
+ line_count+=1
+ domain_names_re=re.compile("^"+TAG_TUPLE.domain_names+"(\[.*\])"+TAG_TUPLE.domain_names+"$")
+ found=domain_names_re.search(line_str)
+ domain_names_lst=eval(found.group(1))
+ range_parser=parse_range_time()
+ print(":domain_names_lst=",domain_names_lst)
+ range_names_lst=range_parser.names()
+ print(":range_names_lst=",range_names_lst)
+ end_range=re.compile(".*]"+TAG_TUPLE.range_out+"$")
+ domain_values_pat="^"+TAG_TUPLE.domain_values+"(\[.*\])"+TAG_TUPLE.domain_values
+ domain_values_re=re.compile(domain_values_pat)
+ domain_range_values=[]#list_of(tuple_of(list_of(domain_values),list_of(range_values)))
+ for line_str in run_file_inp:#{
+ #Body of this loop appends next tuple of(list_of(domain_values),list_of(range_values))
+ line_count+=1
+ if debug_print:
+ print(":line[",line_count,"]=",line_str,end="")
+ found=domain_values_re.search(line_str)
+ if not found:
+ print("*** on line",line_count,"expected '"+TAG_TUPLE.domain_values+"' but found:"+line_str)
+ return 1
+ domain_values_lst=eval(found.group(1))#list_of(domain_values)
+ line_str=run_file_inp.next()#should be 'range_out['
+ line_count+=1
+ range_values_str=""#will be everthing between the TAG_TUPLE.range_out begin/end tags.
+ for line_str in run_file_inp:#{
+ line_count+=1
+ if debug_print:
+ print(":line("+TAG_TUPLE.range_out+")=",line_str,end="")
+ found=end_range.search(line_str)
+ if found:
+ break
+ range_values_str+=line_str
+ #}for line_str in run_file_inp:
+ range_values_lst=range_parser.parse(range_values_str)
+ domain_range_values.append((domain_values_lst,range_values_lst))
+ #^appends tuple_of(list_of(domain_values),list_of(range_values))
+ #}for line_str in run_fle_inp:
+ print_domain_range(domain_range_values)
+ domain_range_out=open('domain_range.pkl','wb')
+ pickle.dump((domain_names_lst,range_names_lst,domain_range_values),domain_range_out)
+ domain_range_out.close()
+ return result
+
+if __name__ == '__main__':
+ ret = main(sys.argv)
+ if ret is not None:
+ sys.exit(ret)
Added: sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_plot.py
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_plot.py 2012-11-16 19:28:55 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+##Purpose:
+## Read pickle file containing plot data and plot it.
+##===============================================
+from __future__ import print_function
+import sys, pickle
+import numpy as np
+import matplotlib.pyplot as plt
+from collections import namedtuple
+from print_domain_range import print_domain_range
+
+def main(argv):
+ result = None
+ if len(argv)>1:
+ pkl_file_inp=open(argv[1],mode='rb')
+ else:
+ print("***expected input pickle filename as argv[1]")
+ return 1
+ (domain_names_lst,range_names_lst,domain_range_values)=pickle.load(pkl_file_inp)
+ print(":domain_names_lst=",domain_names_lst)
+ print(":range_names_lst=",range_names_lst)
+ #print(":domain_range_values=")
+ #print_domain_range(domain_range_values)
+ domain_names_type=namedtuple('domain_names_indices',domain_names_lst)
+ d_ndx=domain_names_type._make(range(len(domain_names_lst)))
+ #print("domain_indices=",d_ndx)
+ filt_dr=filter\
+ ( lambda (d_lst,r_lst)
+ : d_lst[d_ndx.compiler] == 'gcc4_8'
+ and d_lst[d_ndx.TUPLE_SIZE] == 15
+ , domain_range_values
+ )
+ print(":filt_dr=")
+ print_domain_range(filt_dr)
+ return result
+
+if __name__ == '__main__':
+ ret = main(sys.argv)
+ if ret is not None:
+ sys.exit(ret)
Added: sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_tags.py
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/tuple_benchmark_tags.py 2012-11-16 19:28:55 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,19 @@
+"""
+Tags (in sense of xml tags) delimiting the output of tuple_benchmark_run.py
+"""
+from collections import namedtuple
+tag_names=\
+ [ 'compilers'
+ , 'version'
+ , 'domain_names'
+ , 'domain_values'
+ , 'range_out'
+ ]
+tag_tuple=namedtuple\
+ ( 'tag_tuple'
+ , tag_names
+ )
+TAG_TUPLE=tag_tuple._make(tag_names)
+
+if __name__ == '__main__':
+ print TAG_TUPLE
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk