I have a binary file of hex bytes that is only 15 MB and is taking a really long to process with the code below. I import the data to a list and run through them 1 frame (50 bytes) of data at a time. I wonder if there is some improvement I can make to cut down the processing time?
with open(r'C:\binary_file.bin', 'rb') as p:
my_bytes = p.read()
data= list(my_bytes)
frame = 50
sample = 0
processed = []
scales = [
0.0625,
0.0625,
0.00390625,
0.00390625,
3.05176e-05,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
0.0078125,
0.001953125,
0.0001220703,
0.0001220703,
0.0001220703,
3.05176e-05,
1.0,
0.0001220703,
0.001953125,
1.0,
1.0,
1.0
]
while len(data) >= frame:
temp1 = [data[i] + data[i + 1] * 256 for i in range(0, frame - 10, 2)]
temp2 = [i - 65536 if i > 32767 else i for i in temp1]
temp3 = [
int(a * b) if (b == 1 or b == 2) else a * b
for a, b in zip(temp2, scales)
]
temp3 = [round(i, 5) for i in temp3]
temp3.insert(0, sample)
sample += 1
processed += [temp3]
del data[:frame]