M
Matt Taylor
I have a script which runs postprocessing on some data and formats the
results into a table. This is compiled into a C project. The perl script
creates an 800x800 matrix of bits (~800 KB). After creating an enormously
long string, it formats it for C source as follows:
# Pad out the end of the bit string to a byte
$bitstr .= '0' x ((8 - (length($bitstr) % 8)) % 8);
# Create an array of bytes
@bytes = ();
while(length($bitstr) > 0)
{
push(@bytes, sprintf('0x%02X', ord(pack('b8', substr($bitstr, 0, 8)))));
$bitstr = substr($bitstr, 8);
}
# Down here I have code to print the array
This takes several minutes to run under perl 5.8 on my Pentium 4 2.53 GHz. I
was wondering if there was a faster way to do this? Several minutes is
usually acceptable, but in a debug cycle I run this script frequently, and
it would make my life much easier if it were faster.
-Matt
results into a table. This is compiled into a C project. The perl script
creates an 800x800 matrix of bits (~800 KB). After creating an enormously
long string, it formats it for C source as follows:
# Pad out the end of the bit string to a byte
$bitstr .= '0' x ((8 - (length($bitstr) % 8)) % 8);
# Create an array of bytes
@bytes = ();
while(length($bitstr) > 0)
{
push(@bytes, sprintf('0x%02X', ord(pack('b8', substr($bitstr, 0, 8)))));
$bitstr = substr($bitstr, 8);
}
# Down here I have code to print the array
This takes several minutes to run under perl 5.8 on my Pentium 4 2.53 GHz. I
was wondering if there was a faster way to do this? Several minutes is
usually acceptable, but in a debug cycle I run this script frequently, and
it would make my life much easier if it were faster.
-Matt