Working with binary data, S-records (long)

Steven Taschuk staschuk at telusplanet.net
Fri Mar 21 00:42:02 EST 2003


Quoth Hans-Joachim Widmaier:
> [...] Thus I wrote a pure Python
> reader, which looks like (this is the whole class so far):

It would be nice to see a small sample of the input as well.

>     def __init__(self, init=0xff, checkcs=True):
  [...]
>         self.check  = checkcs

Bug!  You test self.checkcs later, not self.check.

>     def readrecord(self, line):
  [...]
>         elif type in ('S3', 'S7'):
>             adr = (long(data[0]) << 24) + (data[2] << 16) \
>                   + (data[3] << 8) + data[4]

Bug?  data[0] and not data[1]?

> On my development machine (1.7 GHz) it's reasonably fast with a file worth
> 100 KB. But I'm afraid it'll suck on our production machines, which run at
> 166 MHz (give or take some). [...]

On my 233 MHz machine your code can process about 2500 records a
second (with some made-up records which might not be realistic).
Would that be acceptable performance?

> Anyway, does anyone see a way to speed this up? I'm not going to inline
> readrecord(), as I don't care about 10 %. I'm asking if you see a real
> flaw in my algorithm.

I see nothing obviously wrong.

-- 
Steven Taschuk             "The world will end if you get this wrong."
staschuk at telusplanet.net     -- "Typesetting Mathematics -- User's Guide",
                                 Brian Kernighan and Lorrinda Cherry





More information about the Python-list mailing list