I changed it to convert each word into an array of integers, just when the program starts. This is the new version of the calcChk2:
def calcChk2(arr)
s = 0
arr.each do |v|
s = $factor * s
s &= 0x7fff
s = s + v
s &= 0x7fff
end
s -= 2000 if s < 1024
s
end
This gets the time down to ~1.4s for 1.6M checksums. Very nice improvement.
EDIT: Further optimization of this code brought the time down to 1.1 s, i.e. 1.45M checksums calculated per second.That’ll do.