digest-crc 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.travis.yml +8 -0
  4. data/ChangeLog.md +116 -1
  5. data/README.md +110 -0
  6. data/Rakefile +25 -1
  7. data/benchmarks.rb +8 -4
  8. data/ext/digest/Rakefile +51 -0
  9. data/ext/digest/compat/ruby.h +11 -0
  10. data/ext/digest/crc12_3gpp/crc12_3gpp.c +68 -0
  11. data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
  12. data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +27 -0
  13. data/ext/digest/crc12_3gpp/extconf.rb +7 -0
  14. data/ext/digest/crc15/crc15.c +54 -0
  15. data/ext/digest/crc15/crc15.h +11 -0
  16. data/ext/digest/crc15/crc15_ext.c +28 -0
  17. data/ext/digest/crc15/extconf.rb +7 -0
  18. data/ext/digest/crc16/crc16.c +70 -0
  19. data/ext/digest/crc16/crc16.h +11 -0
  20. data/ext/digest/crc16/crc16_ext.c +28 -0
  21. data/ext/digest/crc16/extconf.rb +7 -0
  22. data/ext/digest/crc16_ccitt/crc16_ccitt.c +70 -0
  23. data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
  24. data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +28 -0
  25. data/ext/digest/crc16_ccitt/extconf.rb +7 -0
  26. data/ext/digest/crc16_dnp/crc16_dnp.c +54 -0
  27. data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
  28. data/ext/digest/crc16_dnp/crc16_dnp_ext.c +28 -0
  29. data/ext/digest/crc16_dnp/extconf.rb +7 -0
  30. data/ext/digest/crc16_genibus/crc16_genibus.c +70 -0
  31. data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
  32. data/ext/digest/crc16_genibus/crc16_genibus_ext.c +28 -0
  33. data/ext/digest/crc16_genibus/extconf.rb +7 -0
  34. data/ext/digest/crc16_kermit/crc16_kermit.c +70 -0
  35. data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
  36. data/ext/digest/crc16_kermit/crc16_kermit_ext.c +28 -0
  37. data/ext/digest/crc16_kermit/extconf.rb +7 -0
  38. data/ext/digest/crc16_modbus/crc16_modbus.c +70 -0
  39. data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
  40. data/ext/digest/crc16_modbus/crc16_modbus_ext.c +28 -0
  41. data/ext/digest/crc16_modbus/extconf.rb +7 -0
  42. data/ext/digest/crc16_usb/crc16_usb.c +70 -0
  43. data/ext/digest/crc16_usb/crc16_usb.h +8 -0
  44. data/ext/digest/crc16_usb/crc16_usb_ext.c +28 -0
  45. data/ext/digest/crc16_usb/extconf.rb +7 -0
  46. data/ext/digest/crc16_x_25/crc16_x_25.c +70 -0
  47. data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
  48. data/ext/digest/crc16_x_25/crc16_x_25_ext.c +28 -0
  49. data/ext/digest/crc16_x_25/extconf.rb +7 -0
  50. data/ext/digest/crc16_xmodem/crc16_xmodem.c +70 -0
  51. data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
  52. data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +28 -0
  53. data/ext/digest/crc16_xmodem/extconf.rb +7 -0
  54. data/ext/digest/crc16_zmodem/crc16_zmodem.c +70 -0
  55. data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
  56. data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +28 -0
  57. data/ext/digest/crc16_zmodem/extconf.rb +7 -0
  58. data/ext/digest/crc24/crc24.c +70 -0
  59. data/ext/digest/crc24/crc24.h +11 -0
  60. data/ext/digest/crc24/crc24_ext.c +27 -0
  61. data/ext/digest/crc24/extconf.rb +7 -0
  62. data/ext/digest/crc32/crc32.c +69 -0
  63. data/ext/digest/crc32/crc32.h +11 -0
  64. data/ext/digest/crc32/crc32_ext.c +27 -0
  65. data/ext/digest/crc32/extconf.rb +7 -0
  66. data/ext/digest/crc32_bzip2/crc32_bzip2.c +70 -0
  67. data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
  68. data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +27 -0
  69. data/ext/digest/crc32_bzip2/extconf.rb +7 -0
  70. data/ext/digest/crc32_jam/crc32_jam.c +70 -0
  71. data/ext/digest/crc32_jam/crc32_jam.h +8 -0
  72. data/ext/digest/crc32_jam/crc32_jam_ext.c +27 -0
  73. data/ext/digest/crc32_jam/extconf.rb +7 -0
  74. data/ext/digest/crc32_mpeg/crc32_mpeg.c +70 -0
  75. data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
  76. data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +27 -0
  77. data/ext/digest/crc32_mpeg/extconf.rb +7 -0
  78. data/ext/digest/crc32_posix/crc32_posix.c +70 -0
  79. data/ext/digest/crc32_posix/crc32_posix.h +8 -0
  80. data/ext/digest/crc32_posix/crc32_posix_ext.c +27 -0
  81. data/ext/digest/crc32_posix/extconf.rb +7 -0
  82. data/ext/digest/crc32_xfer/crc32_xfer.c +70 -0
  83. data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
  84. data/ext/digest/crc32_xfer/crc32_xfer_ext.c +27 -0
  85. data/ext/digest/crc32_xfer/extconf.rb +7 -0
  86. data/ext/digest/crc32c/crc32c.c +70 -0
  87. data/ext/digest/crc32c/crc32c.h +8 -0
  88. data/ext/digest/crc32c/crc32c_ext.c +27 -0
  89. data/ext/digest/crc32c/extconf.rb +7 -0
  90. data/ext/digest/crc5/crc5.c +54 -0
  91. data/ext/digest/crc5/crc5.h +11 -0
  92. data/ext/digest/crc5/crc5_ext.c +27 -0
  93. data/ext/digest/crc5/extconf.rb +7 -0
  94. data/ext/digest/crc64/crc64.c +102 -0
  95. data/ext/digest/crc64/crc64.h +11 -0
  96. data/ext/digest/crc64/crc64_ext.c +27 -0
  97. data/ext/digest/crc64/extconf.rb +7 -0
  98. data/ext/digest/crc64_jones/crc64_jones.c +102 -0
  99. data/ext/digest/crc64_jones/crc64_jones.h +8 -0
  100. data/ext/digest/crc64_jones/crc64_jones_ext.c +27 -0
  101. data/ext/digest/crc64_jones/extconf.rb +7 -0
  102. data/ext/digest/crc64_xz/crc64_xz.c +102 -0
  103. data/ext/digest/crc64_xz/crc64_xz.h +8 -0
  104. data/ext/digest/crc64_xz/crc64_xz_ext.c +27 -0
  105. data/ext/digest/crc64_xz/extconf.rb +7 -0
  106. data/ext/digest/crc8/crc8.c +54 -0
  107. data/ext/digest/crc8/crc8.h +11 -0
  108. data/ext/digest/crc8/crc8_ext.c +27 -0
  109. data/ext/digest/crc8/extconf.rb +7 -0
  110. data/ext/digest/crc8_1wire/crc8_1wire.c +54 -0
  111. data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
  112. data/ext/digest/crc8_1wire/crc8_1wire_ext.c +27 -0
  113. data/ext/digest/crc8_1wire/extconf.rb +7 -0
  114. data/gemspec.yml +7 -1
  115. data/lib/digest/crc15.rb +4 -0
  116. data/lib/digest/crc16.rb +4 -0
  117. data/lib/digest/crc16_ccitt.rb +4 -0
  118. data/lib/digest/crc16_dnp.rb +4 -0
  119. data/lib/digest/crc16_genibus.rb +4 -0
  120. data/lib/digest/crc16_kermit.rb +4 -0
  121. data/lib/digest/crc16_modbus.rb +4 -0
  122. data/lib/digest/crc16_qt.rb +3 -60
  123. data/lib/digest/crc16_usb.rb +4 -0
  124. data/lib/digest/crc16_x_25.rb +4 -0
  125. data/lib/digest/crc16_xmodem.rb +4 -0
  126. data/lib/digest/crc16_zmodem.rb +4 -0
  127. data/lib/digest/crc24.rb +4 -0
  128. data/lib/digest/crc32.rb +5 -1
  129. data/lib/digest/crc32_bzip2.rb +4 -0
  130. data/lib/digest/crc32_mpeg.rb +4 -0
  131. data/lib/digest/crc32_posix.rb +4 -0
  132. data/lib/digest/crc32_xfer.rb +4 -0
  133. data/lib/digest/crc32c.rb +4 -0
  134. data/lib/digest/crc5.rb +4 -0
  135. data/lib/digest/crc64.rb +4 -0
  136. data/lib/digest/crc64_jones.rb +4 -0
  137. data/lib/digest/crc64_xz.rb +4 -0
  138. data/lib/digest/crc8.rb +4 -0
  139. data/lib/digest/crc8_1wire.rb +4 -0
  140. data/spec/crc16_qt_spec.rb +5 -5
  141. metadata +125 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f92ef55b3e61da5d83aca365fabce146aaa938ff0ee7f380496f30b2909cd8c
4
- data.tar.gz: a34bfa0d5c6b86e29ee5cc27d157a8ea45596e03ffdd7d7d740eaeb9ccca8e6f
3
+ metadata.gz: 9f6be5490751ab763c1fdd99f95a2e4ae0a22a073969623f14170159cb55c5b0
4
+ data.tar.gz: 7f152d312932b784ce074ce9d463bf07dd2bccf5035d9b1bc98dd8c804daa377
5
5
  SHA512:
6
- metadata.gz: cafe8835843afd7873891d6a8c85ba294b8cb846a63641a273844aa50801071d77a92a6e1391e82b9921b199163ab87f9864885ba94f1efaf5a241448a9c0143
7
- data.tar.gz: 3787c83078142822c4d7ff198abbcd5a148061612079877ed8f4e4a3b828a4addb9484c4eb36beb417f30c570c336e1a708d7d9a3735342b3553f1d18e69fb8a
6
+ metadata.gz: 0e9e53d3fc14577e50276ea0f13b663bf62fcafbc2a063491e076bdec99d467f0c57ad0d0cb5b794af1dbadc6794db4070cb6d956b13f4525c5c30af3dea618b
7
+ data.tar.gz: '07198de582c8e350def1763a6c2593ad8a42065c675826c278e3326e81d1a1960b613879a7df017727e12cdc4a4ffc36c15350108a3f6d87076e1f28e4d81afe'
data/.gitignore CHANGED
@@ -3,3 +3,8 @@ doc
3
3
  pkg
4
4
  .bundle
5
5
  .yardoc
6
+ /ext/digest/crc*/Makefile
7
+ /ext/digest/crc*/mkmf.log
8
+ /ext/digest/crc*/extconf.h
9
+ /ext/digest/crc*/*.o
10
+ /ext/digest/crc*/*.so
@@ -2,15 +2,23 @@
2
2
  before_install:
3
3
  - gem update --system
4
4
  - gem install bundler -v "~> 2.0"
5
+
5
6
  language: ruby
6
7
  sudo: false
7
8
  cache:
8
9
  - bundler
10
+
9
11
  rvm:
10
12
  - 2.5
11
13
  - 2.6
14
+ - 2.7
12
15
  - jruby
16
+
13
17
  matrix:
18
+ include:
19
+ - os: linux
20
+ - os: osx
14
21
  allow_failures:
15
22
  - rvm: jruby
23
+
16
24
  script: bundle exec rake spec
@@ -1,3 +1,119 @@
1
+ ### 0.6.1 / 2020-07-02
2
+
3
+ * Fix installation issues under bundler by adding rake as an explicit dependency
4
+ (@rogerluan).
5
+
6
+ ### 0.6.0 / 2020-07-01
7
+
8
+ * Implement _optional_ C extensions for all CRC algorithms, resulting in an
9
+ average performance improvement of ~40x. Note, if for whatever reason the
10
+ C extensions cannot be compiled, they will be skipped and the pure-Ruby
11
+ CRC algorithms will be used instead. If the C extensions were successfully
12
+ compiled, then they will be loaded and override the pure-Ruby CRC methods with
13
+ the C equivalents.
14
+ * Alias {Digest::CRC16QT} to {Digest::CRC16X25}, since they are effectively the same (@dearblue).
15
+ * Fix {Digest::CRC32::WIDTH} (@dearblue).
16
+
17
+ #### pure-Ruby (ruby 2.7.1)
18
+
19
+ Loading Digest::CRC classes ...
20
+ Generating 1000 8Kb lengthed strings ...
21
+ Benchmarking Digest::CRC classes ...
22
+ user system total real
23
+ Digest::CRC1#update 0.412953 0.000000 0.412953 ( 0.414688)
24
+ Digest::CRC5#update 1.116375 0.000003 1.116378 ( 1.120741)
25
+ Digest::CRC8#update 0.994263 0.000013 0.994276 ( 1.001079)
26
+ Digest::CRC8_1Wire#update 0.974115 0.000004 0.974119 ( 0.978186)
27
+ Digest::CRC15#update 1.139402 0.000927 1.140329 ( 1.146608)
28
+ Digest::CRC16#update 0.967836 0.000000 0.967836 ( 0.971792)
29
+ Digest::CRC16CCITT#update 1.118851 0.000000 1.118851 ( 1.123217)
30
+ Digest::CRC16DNP#update 0.922211 0.000000 0.922211 ( 0.925739)
31
+ Digest::CRC16Genibus#update 1.120580 0.000000 1.120580 ( 1.124771)
32
+ Digest::CRC16Modbus#update 0.955612 0.000000 0.955612 ( 0.959463)
33
+ Digest::CRC16QT#update 8.153403 0.000012 8.153415 ( 8.189977)
34
+ Digest::CRC16USB#update 0.952557 0.000000 0.952557 ( 0.956145)
35
+ Digest::CRC16X25#update 0.962295 0.000000 0.962295 ( 0.970401)
36
+ Digest::CRC16XModem#update 1.120531 0.000000 1.120531 ( 1.124494)
37
+ Digest::CRC16ZModem#update 1.124226 0.000000 1.124226 ( 1.128632)
38
+ Digest::CRC24#update 1.126317 0.000000 1.126317 ( 1.130794)
39
+ Digest::CRC32#update 0.960015 0.000000 0.960015 ( 0.964803)
40
+ Digest::CRC32BZip2#update 1.128626 0.000000 1.128626 ( 1.133641)
41
+ Digest::CRC32c#update 0.964047 0.000000 0.964047 ( 0.967456)
42
+ Digest::CRC32Jam#update 0.959141 0.000972 0.960113 ( 0.967444)
43
+ Digest::CRC32MPEG#update 1.131119 0.000002 1.131121 ( 1.137440)
44
+ Digest::CRC32POSIX#update 1.126019 0.000000 1.126019 ( 1.130549)
45
+ Digest::CRC32XFER#update 1.116598 0.000000 1.116598 ( 1.120595)
46
+ Digest::CRC64#update 2.665880 0.000928 2.666808 ( 2.680942)
47
+ Digest::CRC64Jones#update 2.678003 0.000000 2.678003 ( 2.691390)
48
+ Digest::CRC64XZ#update 2.671395 0.000000 2.671395 ( 2.682684)
49
+
50
+ #### pure-Ruby (jruby 9.2.11.1)
51
+
52
+ Loading Digest::CRC classes ...
53
+ Generating 1000 8Kb lengthed strings ...
54
+ Benchmarking Digest::CRC classes ...
55
+ user system total real
56
+ Digest::CRC1#update 0.700000 0.070000 0.770000 ( 0.436112)
57
+ Digest::CRC5#update 1.930000 0.050000 1.980000 ( 1.084749)
58
+ Digest::CRC8#update 1.510000 0.060000 1.570000 ( 0.979123)
59
+ Digest::CRC8_1Wire#update 0.730000 0.030000 0.760000 ( 0.761309)
60
+ Digest::CRC15#update 1.760000 0.080000 1.840000 ( 1.061413)
61
+ Digest::CRC16#update 1.560000 0.030000 1.590000 ( 0.951273)
62
+ Digest::CRC16CCITT#update 1.700000 0.010000 1.710000 ( 1.046854)
63
+ Digest::CRC16DNP#update 1.490000 0.000000 1.490000 ( 0.902434)
64
+ Digest::CRC16Genibus#update 1.820000 0.020000 1.840000 ( 1.030269)
65
+ Digest::CRC16Modbus#update 0.740000 0.010000 0.750000 ( 0.738604)
66
+ Digest::CRC16QT#update 7.280000 0.040000 7.320000 ( 6.399987)
67
+ Digest::CRC16USB#update 0.930000 0.000000 0.930000 ( 0.801541)
68
+ Digest::CRC16X25#update 0.870000 0.000000 0.870000 ( 0.805130)
69
+ Digest::CRC16XModem#update 1.320000 0.010000 1.330000 ( 0.968956)
70
+ Digest::CRC16ZModem#update 1.300000 0.010000 1.310000 ( 0.928303)
71
+ Digest::CRC24#update 1.550000 0.020000 1.570000 ( 1.024450)
72
+ Digest::CRC32#update 1.260000 0.000000 1.260000 ( 0.913814)
73
+ Digest::CRC32BZip2#update 1.210000 0.010000 1.220000 ( 0.919086)
74
+ Digest::CRC32c#update 0.770000 0.010000 0.780000 ( 0.761726)
75
+ Digest::CRC32Jam#update 0.930000 0.000000 0.930000 ( 0.800468)
76
+ Digest::CRC32MPEG#update 1.240000 0.010000 1.250000 ( 0.933962)
77
+ Digest::CRC32POSIX#update 1.290000 0.010000 1.300000 ( 0.925254)
78
+ Digest::CRC32XFER#update 1.270000 0.000000 1.270000 ( 0.920521)
79
+ Digest::CRC64#update 3.480000 0.020000 3.500000 ( 2.883794)
80
+ Digest::CRC64Jones#update 2.740000 0.000000 2.740000 ( 2.738251)
81
+ Digest::CRC64XZ#update 2.780000 0.010000 2.790000 ( 2.715833)
82
+
83
+
84
+ #### C extensions (ruby 2.7.1)
85
+
86
+ Loading Digest::CRC classes ...
87
+ Generating 1000 8Kb lengthed strings ...
88
+ Benchmarking Digest::CRC classes ...
89
+ user system total real
90
+ Digest::CRC1#update 0.407438 0.000000 0.407438 ( 0.410495)
91
+ Digest::CRC5#update 0.022873 0.000000 0.022873 ( 0.023796)
92
+ Digest::CRC8#update 0.020129 0.000000 0.020129 ( 0.020887)
93
+ Digest::CRC8_1Wire#update 0.020106 0.000000 0.020106 ( 0.020897)
94
+ Digest::CRC15#update 0.028765 0.000003 0.028768 ( 0.029549)
95
+ Digest::CRC16#update 0.022176 0.000856 0.023032 ( 0.023153)
96
+ Digest::CRC16CCITT#update 0.028570 0.000000 0.028570 ( 0.028691)
97
+ Digest::CRC16DNP#update 0.023240 0.000001 0.023241 ( 0.024008)
98
+ Digest::CRC16Genibus#update 0.028692 0.000000 0.028692 ( 0.029575)
99
+ Digest::CRC16Modbus#update 0.023928 0.000000 0.023928 ( 0.024859)
100
+ Digest::CRC16QT#update 7.965822 0.000968 7.966790 ( 8.001781)
101
+ Digest::CRC16USB#update 0.023448 0.000001 0.023449 ( 0.024420)
102
+ Digest::CRC16X25#update 0.023061 0.000000 0.023061 ( 0.023861)
103
+ Digest::CRC16XModem#update 0.029407 0.000000 0.029407 ( 0.030583)
104
+ Digest::CRC16ZModem#update 0.029522 0.000000 0.029522 ( 0.030438)
105
+ Digest::CRC24#update 0.029528 0.000000 0.029528 ( 0.030504)
106
+ Digest::CRC32#update 0.023306 0.000000 0.023306 ( 0.024278)
107
+ Digest::CRC32BZip2#update 0.026346 0.000000 0.026346 ( 0.027293)
108
+ Digest::CRC32c#update 0.023525 0.000000 0.023525 ( 0.024489)
109
+ Digest::CRC32Jam#update 0.023348 0.000000 0.023348 ( 0.023477)
110
+ Digest::CRC32MPEG#update 0.026287 0.000000 0.026287 ( 0.027394)
111
+ Digest::CRC32POSIX#update 0.026063 0.000000 0.026063 ( 0.026986)
112
+ Digest::CRC32XFER#update 0.026374 0.000000 0.026374 ( 0.027314)
113
+ Digest::CRC64#update 0.023523 0.000000 0.023523 ( 0.024484)
114
+ Digest::CRC64Jones#update 0.023479 0.000000 0.023479 ( 0.024432)
115
+ Digest::CRC64XZ#update 0.024146 0.000000 0.024146 ( 0.025129)
116
+
1
117
  ### 0.5.1 / 2020-03-03
2
118
 
3
119
  * Fixed XOR logic in {Digest::CRC16Genibus}.
@@ -63,4 +179,3 @@
63
179
  * CRC32
64
180
  * CRC32 Mpeg
65
181
  * CRC64
66
-
data/README.md CHANGED
@@ -44,6 +44,9 @@ module.
44
44
  * {Digest::CRC64XZ CRC64 XZ}
45
45
  * Pure Ruby implementation.
46
46
  * Provides CRC Tables for optimized calculations.
47
+ * Supports _optional_ C extensions which increases performance by ~40x.
48
+ * If the C extensions cannot be compiled for whatever reason, digest-crc
49
+ will automatically fallback to the pure-Ruby implementation.
47
50
 
48
51
  ## Install
49
52
 
@@ -116,6 +119,113 @@ module Digest
116
119
  end
117
120
  ```
118
121
 
122
+ ## Benchmarks
123
+
124
+ ### Pure Ruby (ruby 2.7.1)
125
+
126
+ $ bundle exec rake clean
127
+ $ bundle exec ./benchmarks.rb
128
+ Loading Digest::CRC classes ...
129
+ Generating 1000 8Kb lengthed strings ...
130
+ Benchmarking Digest::CRC classes ...
131
+ user system total real
132
+ Digest::CRC1#update 0.349756 0.000002 0.349758 ( 0.351427)
133
+ Digest::CRC5#update 1.175206 0.000049 1.175255 ( 1.180975)
134
+ Digest::CRC8#update 1.023536 0.000015 1.023551 ( 1.029017)
135
+ Digest::CRC8_1Wire#update 1.012156 0.000000 1.012156 ( 1.017342)
136
+ Digest::CRC15#update 1.187286 0.000005 1.187291 ( 1.193634)
137
+ Digest::CRC16#update 0.998527 0.000013 0.998540 ( 1.003940)
138
+ Digest::CRC16CCITT#update 1.179864 0.000005 1.179869 ( 1.186134)
139
+ Digest::CRC16DNP#update 1.018969 0.000003 1.018972 ( 1.025248)
140
+ Digest::CRC16Genibus#update 1.196754 0.000065 1.196819 ( 1.203605)
141
+ Digest::CRC16Modbus#update 1.007367 0.000000 1.007367 ( 1.012325)
142
+ Digest::CRC16X25#update 1.044127 0.000000 1.044127 ( 1.052010)
143
+ Digest::CRC16USB#update 1.012804 0.000000 1.012804 ( 1.018324)
144
+ Digest::CRC16X25#update 1.009694 0.000000 1.009694 ( 1.015890)
145
+ Digest::CRC16XModem#update 1.210814 0.000000 1.210814 ( 1.217951)
146
+ Digest::CRC16ZModem#update 1.175239 0.000000 1.175239 ( 1.181395)
147
+ Digest::CRC24#update 1.207431 0.000000 1.207431 ( 1.213373)
148
+ Digest::CRC32#update 1.012334 0.000000 1.012334 ( 1.017671)
149
+ Digest::CRC32BZip2#update 1.190351 0.000000 1.190351 ( 1.196567)
150
+ Digest::CRC32c#update 1.021147 0.000000 1.021147 ( 1.027035)
151
+ Digest::CRC32Jam#update 1.002365 0.000000 1.002365 ( 1.007202)
152
+ Digest::CRC32MPEG#update 1.161925 0.000000 1.161925 ( 1.168058)
153
+ Digest::CRC32POSIX#update 1.191860 0.000967 1.192827 ( 1.198722)
154
+ Digest::CRC32XFER#update 1.217692 0.000000 1.217692 ( 1.224075)
155
+ Digest::CRC64#update 3.084106 0.000000 3.084106 ( 3.106840)
156
+ Digest::CRC64Jones#update 3.016687 0.000000 3.016687 ( 3.038963)
157
+ Digest::CRC64XZ#update 3.019690 0.000000 3.019690 ( 3.040971)
158
+
159
+ ### C extensions (ruby 2.7.1)
160
+ o
161
+ $ bundle exec rake build:c_exts
162
+ ...
163
+ $ bundle exec ./benchmarks.rb
164
+ Loading Digest::CRC classes ...
165
+ Generating 1000 8Kb lengthed strings ...
166
+ Benchmarking Digest::CRC classes ...
167
+ user system total real
168
+ Digest::CRC1#update 0.356025 0.000016 0.356041 ( 0.365345)
169
+ Digest::CRC5#update 0.023957 0.000001 0.023958 ( 0.024835)
170
+ Digest::CRC8#update 0.021254 0.000007 0.021261 ( 0.024647)
171
+ Digest::CRC8_1Wire#update 0.039129 0.000000 0.039129 ( 0.042417)
172
+ Digest::CRC15#update 0.030285 0.000000 0.030285 ( 0.030560)
173
+ Digest::CRC16#update 0.023003 0.000000 0.023003 ( 0.023267)
174
+ Digest::CRC16CCITT#update 0.028207 0.000000 0.028207 ( 0.028467)
175
+ Digest::CRC16DNP#update 0.022861 0.000000 0.022861 ( 0.023111)
176
+ Digest::CRC16Genibus#update 0.028041 0.000000 0.028041 ( 0.028359)
177
+ Digest::CRC16Modbus#update 0.022931 0.000009 0.022940 ( 0.023560)
178
+ Digest::CRC16X25#update 0.022808 0.000000 0.022808 ( 0.023054)
179
+ Digest::CRC16USB#update 0.022258 0.000882 0.023140 ( 0.023418)
180
+ Digest::CRC16X25#update 0.022816 0.000000 0.022816 ( 0.023084)
181
+ Digest::CRC16XModem#update 0.027984 0.000000 0.027984 ( 0.028269)
182
+ Digest::CRC16ZModem#update 0.027968 0.000000 0.027968 ( 0.028214)
183
+ Digest::CRC24#update 0.028426 0.000000 0.028426 ( 0.028687)
184
+ Digest::CRC32#update 0.022805 0.000000 0.022805 ( 0.023043)
185
+ Digest::CRC32BZip2#update 0.025519 0.000000 0.025519 ( 0.025797)
186
+ Digest::CRC32c#update 0.022807 0.000000 0.022807 ( 0.023069)
187
+ Digest::CRC32Jam#update 0.023006 0.000000 0.023006 ( 0.023231)
188
+ Digest::CRC32MPEG#update 0.025536 0.000000 0.025536 ( 0.025861)
189
+ Digest::CRC32POSIX#update 0.025557 0.000000 0.025557 ( 0.025841)
190
+ Digest::CRC32XFER#update 0.025310 0.000000 0.025310 ( 0.025599)
191
+ Digest::CRC64#update 0.023182 0.000000 0.023182 ( 0.023421)
192
+ Digest::CRC64Jones#update 0.022916 0.000000 0.022916 ( 0.023139)
193
+ Digest::CRC64XZ#update 0.022879 0.000000 0.022879 ( 0.023131)
194
+
195
+ ### Pure Ruby (jruby 9.2.12.0)
196
+
197
+ $ bundle exec ./benchmarks.rb
198
+ Loading Digest::CRC classes ...
199
+ Generating 1000 8Kb lengthed strings ...
200
+ Benchmarking Digest::CRC classes ...
201
+ user system total real
202
+ Digest::CRC1#update 1.030000 0.090000 1.120000 ( 0.511189)
203
+ Digest::CRC5#update 1.620000 0.060000 1.680000 ( 1.096031)
204
+ Digest::CRC8#update 1.560000 0.070000 1.630000 ( 1.083921)
205
+ Digest::CRC8_1Wire#update 0.930000 0.040000 0.970000 ( 0.927024)
206
+ Digest::CRC15#update 1.590000 0.070000 1.660000 ( 1.132566)
207
+ Digest::CRC16#update 1.650000 0.060000 1.710000 ( 1.074508)
208
+ Digest::CRC16CCITT#update 1.610000 0.060000 1.670000 ( 1.190860)
209
+ Digest::CRC16DNP#update 1.270000 0.010000 1.280000 ( 0.938132)
210
+ Digest::CRC16Genibus#update 1.620000 0.030000 1.650000 ( 1.148556)
211
+ Digest::CRC16Modbus#update 1.070000 0.020000 1.090000 ( 0.881455)
212
+ Digest::CRC16X25#update 1.110000 0.010000 1.120000 ( 0.945366)
213
+ Digest::CRC16USB#update 1.140000 0.000000 1.140000 ( 0.984367)
214
+ Digest::CRC16X25#update 0.920000 0.010000 0.930000 ( 0.872541)
215
+ Digest::CRC16XModem#update 1.530000 0.010000 1.540000 ( 1.092838)
216
+ Digest::CRC16ZModem#update 1.720000 0.010000 1.730000 ( 1.164787)
217
+ Digest::CRC24#update 1.810000 0.020000 1.830000 ( 1.084953)
218
+ Digest::CRC32#update 1.590000 0.010000 1.600000 ( 1.105553)
219
+ Digest::CRC32BZip2#update 1.520000 0.010000 1.530000 ( 1.070839)
220
+ Digest::CRC32c#update 0.960000 0.010000 0.970000 ( 0.881989)
221
+ Digest::CRC32Jam#update 1.030000 0.010000 1.040000 ( 0.907208)
222
+ Digest::CRC32MPEG#update 1.420000 0.010000 1.430000 ( 0.994035)
223
+ Digest::CRC32POSIX#update 1.530000 0.020000 1.550000 ( 1.106366)
224
+ Digest::CRC32XFER#update 1.650000 0.010000 1.660000 ( 1.097647)
225
+ Digest::CRC64#update 3.440000 0.030000 3.470000 ( 2.771806)
226
+ Digest::CRC64Jones#update 2.630000 0.010000 2.640000 ( 2.628016)
227
+ Digest::CRC64XZ#update 3.200000 0.020000 3.220000 ( 2.913442)
228
+
119
229
  ## Thanks
120
230
 
121
231
  Special thanks go out to the [pycrc](http://www.tty1.net/pycrc/) library
data/Rakefile CHANGED
@@ -10,8 +10,32 @@ require 'rake'
10
10
  require 'rubygems/tasks'
11
11
  Gem::Tasks.new
12
12
 
13
+ namespace :build do
14
+ desc "Builds the C extensions"
15
+ task :c_exts do
16
+ Dir.chdir('ext/digest') { sh 'rake' }
17
+ end
18
+ end
19
+
20
+ require 'rake/clean'
21
+ CLEAN.include('ext/digest/crc*/extconf.h')
22
+ CLEAN.include('ext/digest/crc*/Makefile')
23
+ CLEAN.include('ext/digest/crc*/*.o')
24
+ CLEAN.include('ext/digest/crc*/*.so')
25
+
13
26
  require 'rspec/core/rake_task'
14
- RSpec::Core::RakeTask.new
27
+ namespace :spec do
28
+ RSpec::Core::RakeTask.new(:pure)
29
+ task :pure => :clean
30
+
31
+ if RUBY_ENGINE == 'ruby'
32
+ RSpec::Core::RakeTask.new(:c_exts)
33
+ task :c_exts => 'build:c_exts'
34
+ end
35
+ end
36
+
37
+ task :spec => 'spec:pure'
38
+ task :spec => 'spec:c_exts' if RUBY_ENGINE == 'ruby'
15
39
  task :test => :spec
16
40
  task :default => :spec
17
41
 
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'benchmark'
3
- $LOAD_PATH.unshift(File.expand_path('lib'))
3
+ $LOAD_PATH.unshift(File.expand_path('../ext',__FILE__))
4
+ $LOAD_PATH.unshift(File.expand_path('../lib',__FILE__))
4
5
 
5
6
  CRCs = {
6
7
  'crc1' => 'CRC1',
@@ -34,9 +35,12 @@ CRCs = {
34
35
  puts "Loading Digest::CRC classes ..."
35
36
  CRCs.each_key { |crc| require "digest/#{crc}" }
36
37
 
37
- puts "Generating random lengthed strings ..."
38
- SAMPLES = Array.new(100) do
39
- Array.new(100 * rand(1024)) { rand(256).chr }.join
38
+ N = 1000
39
+ BLOCK_SIZE = 8 * 1024
40
+
41
+ puts "Generating #{N} #{BLOCK_SIZE / 1024}Kb lengthed strings ..."
42
+ SAMPLES = Array.new(N) do
43
+ Array.new(BLOCK_SIZE) { rand(256).chr }.join
40
44
  end
41
45
 
42
46
  puts "Benchmarking Digest::CRC classes ..."
@@ -0,0 +1,51 @@
1
+ def fail_gracefully(message)
2
+ warn "#{message}. Failing gracefully ..."
3
+ exit
4
+ end
5
+
6
+ unless RUBY_ENGINE == 'ruby'
7
+ fail_gracefully "C extensions for #{RUBY_ENGINE} currently not supported"
8
+ end
9
+
10
+ begin
11
+ require "mkmf"
12
+ rescue LoadError
13
+ fail_gracefully "mkmf is not installed"
14
+ end
15
+
16
+ MAKE = $make # set by mkmf
17
+
18
+ def make(target=nil)
19
+ if target then sh(MAKE,target)
20
+ else sh(MAKE)
21
+ end
22
+ end
23
+
24
+ CRCS = Dir['crc*']
25
+ DLEXT = MakeMakefile::CONFIG['DLEXT']
26
+
27
+ CRCS.each do |crc|
28
+ crc_ext = "#{crc}_ext"
29
+
30
+ file "#{crc}/Makefile" => "#{crc}/extconf.rb" do
31
+ Dir.chdir(crc) do
32
+ unless ruby('-S', 'extconf.rb')
33
+ fail_gracefully "extconf.rb failed"
34
+ end
35
+ end
36
+ end
37
+
38
+ crc_ext_lib = "#{crc}_ext.#{DLEXT}"
39
+
40
+ file "#{crc}/#{crc_ext_lib}" => "#{crc}/Makefile" do
41
+ Dir.chdir(crc) do
42
+ make 'clean'
43
+
44
+ unless make
45
+ fail_gracefully "Unable to build C extensions"
46
+ end
47
+ end
48
+ end
49
+
50
+ task :default => "#{crc}/#{crc_ext_lib}"
51
+ end
@@ -0,0 +1,11 @@
1
+ #ifndef _DIGEST_COMPAT_RUBY_H_
2
+ #define _DIGEST_COMPAT_RUBY_H_
3
+
4
+ #include <ruby.h>
5
+
6
+ // HACK: define USHORT2NUM for Ruby < 2.6
7
+ #ifndef USHORT2NUM
8
+ #define USHORT2NUM(x) RB_INT2FIX(x)
9
+ #endif
10
+
11
+ #endif
@@ -0,0 +1,68 @@
1
+ /**
2
+ * \file
3
+ * Functions and types for CRC checks.
4
+ *
5
+ * Generated on Sat Feb 29 02:30:42 2020
6
+ * by pycrc v0.9.2, https://pycrc.org
7
+ * using the configuration:
8
+ * - Width = 12
9
+ * - Poly = 0x80f
10
+ * - XorIn = 0x000
11
+ * - ReflectIn = False
12
+ * - XorOut = 0x000
13
+ * - ReflectOut = True
14
+ * - Algorithm = table-driven
15
+ */
16
+
17
+ #include "crc12_3gpp.h"
18
+
19
+ /**
20
+ * Static table used for the table_driven implementation.
21
+ */
22
+ static const crc12_t crc12_table[256] = {
23
+ 0x000, 0x80f, 0x811, 0x01e, 0x82d, 0x022, 0x03c, 0x833, 0x855, 0x05a, 0x044, 0x84b, 0x078, 0x877, 0x869, 0x066,
24
+ 0x8a5, 0x0aa, 0x0b4, 0x8bb, 0x088, 0x887, 0x899, 0x096, 0x0f0, 0x8ff, 0x8e1, 0x0ee, 0x8dd, 0x0d2, 0x0cc, 0x8c3,
25
+ 0x945, 0x14a, 0x154, 0x95b, 0x168, 0x967, 0x979, 0x176, 0x110, 0x91f, 0x901, 0x10e, 0x93d, 0x132, 0x12c, 0x923,
26
+ 0x1e0, 0x9ef, 0x9f1, 0x1fe, 0x9cd, 0x1c2, 0x1dc, 0x9d3, 0x9b5, 0x1ba, 0x1a4, 0x9ab, 0x198, 0x997, 0x989, 0x186,
27
+ 0xa85, 0x28a, 0x294, 0xa9b, 0x2a8, 0xaa7, 0xab9, 0x2b6, 0x2d0, 0xadf, 0xac1, 0x2ce, 0xafd, 0x2f2, 0x2ec, 0xae3,
28
+ 0x220, 0xa2f, 0xa31, 0x23e, 0xa0d, 0x202, 0x21c, 0xa13, 0xa75, 0x27a, 0x264, 0xa6b, 0x258, 0xa57, 0xa49, 0x246,
29
+ 0x3c0, 0xbcf, 0xbd1, 0x3de, 0xbed, 0x3e2, 0x3fc, 0xbf3, 0xb95, 0x39a, 0x384, 0xb8b, 0x3b8, 0xbb7, 0xba9, 0x3a6,
30
+ 0xb65, 0x36a, 0x374, 0xb7b, 0x348, 0xb47, 0xb59, 0x356, 0x330, 0xb3f, 0xb21, 0x32e, 0xb1d, 0x312, 0x30c, 0xb03,
31
+ 0xd05, 0x50a, 0x514, 0xd1b, 0x528, 0xd27, 0xd39, 0x536, 0x550, 0xd5f, 0xd41, 0x54e, 0xd7d, 0x572, 0x56c, 0xd63,
32
+ 0x5a0, 0xdaf, 0xdb1, 0x5be, 0xd8d, 0x582, 0x59c, 0xd93, 0xdf5, 0x5fa, 0x5e4, 0xdeb, 0x5d8, 0xdd7, 0xdc9, 0x5c6,
33
+ 0x440, 0xc4f, 0xc51, 0x45e, 0xc6d, 0x462, 0x47c, 0xc73, 0xc15, 0x41a, 0x404, 0xc0b, 0x438, 0xc37, 0xc29, 0x426,
34
+ 0xce5, 0x4ea, 0x4f4, 0xcfb, 0x4c8, 0xcc7, 0xcd9, 0x4d6, 0x4b0, 0xcbf, 0xca1, 0x4ae, 0xc9d, 0x492, 0x48c, 0xc83,
35
+ 0x780, 0xf8f, 0xf91, 0x79e, 0xfad, 0x7a2, 0x7bc, 0xfb3, 0xfd5, 0x7da, 0x7c4, 0xfcb, 0x7f8, 0xff7, 0xfe9, 0x7e6,
36
+ 0xf25, 0x72a, 0x734, 0xf3b, 0x708, 0xf07, 0xf19, 0x716, 0x770, 0xf7f, 0xf61, 0x76e, 0xf5d, 0x752, 0x74c, 0xf43,
37
+ 0xec5, 0x6ca, 0x6d4, 0xedb, 0x6e8, 0xee7, 0xef9, 0x6f6, 0x690, 0xe9f, 0xe81, 0x68e, 0xebd, 0x6b2, 0x6ac, 0xea3,
38
+ 0x660, 0xe6f, 0xe71, 0x67e, 0xe4d, 0x642, 0x65c, 0xe53, 0xe35, 0x63a, 0x624, 0xe2b, 0x618, 0xe17, 0xe09, 0x606
39
+ };
40
+
41
+ crc12_t crc_reflect(crc12_t data, size_t data_len)
42
+ {
43
+ unsigned int i;
44
+ crc12_t ret = data & 0x01;
45
+
46
+ for (i = 1; i < data_len; i++)
47
+ {
48
+ data >>= 1;
49
+ ret = (ret << 1) | (data & 0x01);
50
+ }
51
+
52
+ return ret;
53
+ }
54
+
55
+ crc12_t crc12_3gpp_update(crc12_t crc, const void *data, size_t data_len)
56
+ {
57
+ const unsigned char *d = (const unsigned char *)data;
58
+ unsigned int tbl_idx;
59
+
60
+ while (data_len--)
61
+ {
62
+ tbl_idx = ((crc >> 4) ^ *d) & 0xff;
63
+ crc = (crc12_table[tbl_idx] ^ (crc << 8)) & 0xfff;
64
+ d++;
65
+ }
66
+
67
+ return crc & 0xfff;
68
+ }