src/reportlab/lib/rl_accel.py
changeset 4551 d357e2acc856
parent 4413 dec33c7e7922
child 4567 5612ef8ef0a8
equal deleted inserted replaced
4550:80dd9e83dad9 4551:d357e2acc856
    19 import reportlab
    19 import reportlab
    20 testing = getattr(reportlab,'_rl_testing',False)
    20 testing = getattr(reportlab,'_rl_testing',False)
    21 del reportlab
    21 del reportlab
    22 
    22 
    23 for fn in __all__:
    23 for fn in __all__:
       
    24     D={}
    24     try:
    25     try:
    25         exec('from reportlab.lib._rl_accel import %s as f' % fn)
    26         exec('from reportlab.lib._rl_accel import %s as f' % fn,D)
    26         _c_funcs[fn] = f
    27         _c_funcs[fn] = D['f']
    27         if testing: _py_funcs[fn] = None
    28         if testing: _py_funcs[fn] = None
    28     except ImportError:
    29     except ImportError:
    29         _py_funcs[fn] = None
    30         _py_funcs[fn] = None
       
    31     del D
    30 
    32 
    31 if _py_funcs:
    33 if _py_funcs:
    32     from reportlab.lib.utils import isBytes, isUnicode, isSeq, isPy3, rawBytes, asNative, asUnicode, asBytes
    34     from reportlab.lib.utils import isBytes, isUnicode, isSeq, isPy3, rawBytes, asNative, asUnicode, asBytes
    33     from math import log
    35     from math import log
    34     from struct import unpack
    36     from struct import unpack
   332         raise RuntimeError('function %s is not properly defined' % fn)
   334         raise RuntimeError('function %s is not properly defined' % fn)
   333     G[fn] = f
   335     G[fn] = f
   334 del fn, f, G
   336 del fn, f, G
   335 
   337 
   336 if __name__=='__main__':
   338 if __name__=='__main__':
   337     import sys, os
   339     import sys, os, subprocess
   338     for modname in 'reportlab.lib.rl_accel','reportlab.lib._rl_accel':
   340     for modname in 'reportlab.lib.rl_accel','reportlab.lib._rl_accel':
   339         for cmd  in (
   341         for cmd  in (
   340             #"unicode2T1('abcde fghi . jkl ; mno',fonts)",
   342             #"unicode2T1('abcde fghi . jkl ; mno',fonts)",
   341             #"unicode2T1(u'abcde fghi . jkl ; mno',fonts)",
   343             #"unicode2T1(u'abcde fghi . jkl ; mno',fonts)",
   342             "_instanceStringWidthU(font,'abcde fghi . jkl ; mno',10)",
   344             "instanceStringWidthT1(font,'abcde fghi . jkl ; mno',10)",
   343             "_instanceStringWidthU(font,u'abcde fghi . jkl ; mno',10)",
   345             "instanceStringWidthT1(font,u'abcde fghi . jkl ; mno',10)",
   344             ):
   346             ):
   345             print('%s %s' % (modname,cmd))
   347             print('%s %s' % (modname,cmd))
   346             s=';'.join((
   348             s=';'.join((
   347                 "from reportlab.pdfbase.pdfmetrics import getFont",
   349                 "from reportlab.pdfbase.pdfmetrics import getFont",
   348                 "from %s import unicode2T1,_instanceStringWidthU" % modname,
   350                 "from %s import unicode2T1,instanceStringWidthT1" % modname,
   349                 "fonts=[getFont('Helvetica')]+getFont('Helvetica').substitutionFonts""",
   351                 "fonts=[getFont('Helvetica')]+getFont('Helvetica').substitutionFonts""",
   350                 "font=fonts[0]",
   352                 "font=fonts[0]",
   351                 ))
   353                 ))
   352             os.system('%s -m timeit -s"%s" "%s"' % (sys.executable,s,cmd))
   354             subprocess.check_call([sys.executable,'-mtimeit','-s',s,cmd])