UltraFast CrC32 needs testing!
Blitz3D Forums/Blitz3D Programming/UltraFast CrC32 needs testing!
| ||
Hi all, i needed crc32 code so i decided to use the code supplied by MrCredo in the code archives. The code is well written but very slow. Unmodified it takes on average 25-30 seconds to calculate the crc for a 20mb file. Ive added stuff to do this from memory and managed to speed it up by around 20 times but it only works for files that will fit into the remaining physical ram. Im trying to get it to do it in 10mb chuncks from memory but its proving harder than i thought. I'll post the code for people to hack :) *********************************************************** Dim crc_table(255) crc_init() Print Hex$(crc_file("c:\test.exe")) WaitKey Function crc_init() Local i Local j Local value For i=0 To 255 value=i For j=0 To 7 If (value And $1) Then value=(value Shr 1) Xor $EDB88320 Else value=(value Shr 1) EndIf Next crc_table(i)=value Next End Function Function crc_file(name$) Local byte Local crc Local file Local size Local a crc=$FFFFFFFF file=ReadFile(name$) size=FileSize("c:\test.exe") If file=0 Then Return bank=CreateBank(size) ReadBytes bank,file,0,size CloseFile file st#=MilliSecs() While a<>size crc=(crc Shr 8) Xor crc_table(PeekByte(bank,a) Xor (crc And $FF)) a=a+1 Wend et#=MilliSecs() Print "CRC32 Checked in "+(et#-st#)/1000+" Seconds" FreeBank bank Return ~crc End Function |
| ||
If you look around for the blitzsys.dll it has functions to crc files or banks of data... it may be faster, but would have to time both methods :) |
| ||
What is crc if you don't mind me asking? :o) |
| ||
CRC |
| ||
Ah, thanks man :o) |
| ||
Thanx Ross i might look into later if i need the extra speed, 0.2 seconds is ok for a 20mb file for now i hope |
| ||
Nice. I see you put in the 'closefile' mrcredo missed in his original code. ;) |