Use String#unpack for better extraction of words from segments
postmodern opened this issue · 1 comments
postmodern commented
String#unpack
should be faster and provide more format options (such as floats). Segments will also have to be padded with \0
bytes.
postmodern commented
Did an experiment with having #each_word
read each byte into a String buffer then call String#unpack
and it's slightly slower than just doing bitwise math:
String#unpack
user system total real
Hexdump.dump (output) 10.810911 0.000000 10.810911 ( 10.869495)
Hexdump.dump width=256 (output) 9.483426 0.003832 9.487258 ( 9.543299)
Hexdump.dump ascii=true (output) 10.606700 0.000000 10.606700 ( 10.641688)
Hexdump.dump word_size=2 (output) 19.317735 0.000010 19.317745 ( 19.392457)
Hexdump.dump word_size=4 (output) 18.739036 0.000013 18.739049 ( 18.826742)
Hexdump.dump word_size=8 (output) 10.603023 0.000004 10.603027 ( 10.643707)
Hexdump.dump (block) 5.508398 0.000000 5.508398 ( 5.524796)
Hexdump.dump width=256 (block) 5.540716 0.000000 5.540716 ( 5.557970)
Hexdump.dump ascii=true (block) 6.221936 0.000000 6.221936 ( 6.245208)
Hexdump.dump word_size=2 (block) 15.909723 0.000000 15.909723 ( 15.967684)
Hexdump.dump word_size=4 (block) 15.541515 0.000000 15.541515 ( 15.605455)
Hexdump.dump word_size=8 (block) 8.204565 0.000858 8.205423 ( 8.232888)
Bitshifting
user system total real
Hexdump.dump (output) 10.582241 0.000055 10.582296 ( 10.626448)
Hexdump.dump width=256 (output) 8.836189 0.008962 8.845151 ( 8.877264)
Hexdump.dump ascii=true (output) 11.071560 0.000000 11.071560 ( 11.115871)
Hexdump.dump word_size=2 (output) 16.192893 0.002944 16.195837 ( 16.283254)
Hexdump.dump word_size=4 (output) 13.824119 0.000981 13.825100 ( 13.883479)
Hexdump.dump word_size=8 (output) 7.523130 0.000001 7.523131 ( 7.554442)
Hexdump.dump (block) 5.918965 0.000000 5.918965 ( 5.951641)
Hexdump.dump width=256 (block) 5.788696 0.000000 5.788696 ( 5.811731)
Hexdump.dump ascii=true (block) 6.425460 0.000000 6.425460 ( 6.444785)
Hexdump.dump word_size=2 (block) 12.501186 0.002875 12.504061 ( 12.588385)
Hexdump.dump word_size=4 (block) 10.756808 0.000000 10.756808 ( 10.798557)
Hexdump.dump word_size=8 (block) 5.307631 0.000000 5.307631 ( 5.324436)