Hi Monks,
I have written a (working) perl program, but it is quite slow. I have troubles to find out why. Is there a better way to find out why, than guess and try ?? How do you start a speed analyses to find out why a program is slow ?
Thanks for your help !!!
My program reads a complete binary file into $f (Not show in the code fragment). Than it decodes following structure:
The first byte is the first data byte. (range from 0 to 59, 255 means datastream is over)
The second byte defines how many "position bytes" bytes are following. (binary: 1=position byte follows, so 1 to max 8 position bytes, 0=position byte equal to 0x00 skipped)
The position bytes define which data bytes are changed in this data set. (binary: 1=data byte changed, so max 64 data bytes)
Now the databytes follows (one for each binary 1 in a position byte), followed by a CRC byte of this dataset.
Than the next data set is comming, until 255 is following.
The program checks the data and does statistics. (Not shown in my code fragment here. Also when this part is commented out, the program is too slow !,)
Hope this description was not too short for this data structure.
Please find my program here:
$crc=255; $data[0]=readByte(); do { $_=sprintf("%08b",readByte()); + # BYTE1 $byte2=''; while (m/(.)/g) { if ($1 == 0) { $byte2.='00000000';} else { $byte2.=sprintf("%08b",readByte());} + # positions bytes } $data[pos($byte2)]=readByte() while ($byte2=~m/(1)/g); + # put data value into @data on the correct position readByte(); if ($crc>0) {print "ERROR: CRC (POS:".pos($f).')'; ex +it; } # crc check $crc=255; # ---- USE DATA => DELETED -------- $data[0]=readByte(); } while ($data[0]<255); } sub readByte { unless ($f=~m/(.)/gs) {print "Last data structure not complete !"; e +xit;} my $x=ord($1); $crc^=$x; # CRC for my $r(1..8) { if (($crc&1)>0) {$crc=($crc>>1)^0x8c;} else {$crc=$crc>>1;} } return ($x); }
In reply to How to find out, why my perl code is slow. by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |