[Tutor] script still too slow

alan.gauld@bt.com alan.gauld@bt.com
Thu Feb 27 13:48:01 2003


>     def evaluate_token(self,token):
>         if token == '{':
>             self.__bracket_count = self.__bracket_count + 1
>             num = '%04d' % self.__bracket_count

This line can come out coz its just creating a temporary string which 
is promptly thrown away!

>             token = 'ob<nu<nu<nu<%(num)s<{\n' % vars()
>         elif token == '}':
>             num = '%04d' % self.__bracket_count

Same here!

>             token = 'cb<nu<nu<nu<%(num)s<}\n' % vars()
>             self.__bracket_count = self.__bracket_count - 1
>         elif token == r'\{':
>             token = 'tx<es<nu<nu<nu<{\n'
>         elif token == r'\}':
>             token = 'tx<es<nu<nu<nu<}\n'
>         elif token == r'\\': # double or escaped \
>             token = 'tx<es<nu<nu<nu<\\\n'
>         elif token[0:1] != '\\': # single \

You could just use token[0] here which will be marginally faster...

>             token = 'tx<nu<nu<nu<nu<%(token)s\n' % vars()
>         else:
>             token = self.evaluate_cw(token)

Can we see this function too? Since its time will be included 
with the outer function we need to see it. Also do we know how 
often this default function gets called? - Your profile output 
should say.

Overall I would expect Python to be slightly slower at this kind 
of task, but only by 20-50% not 300%!

Alan g.