digest-crc 0.5.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/integration.yml +26 -0
  3. data/.github/workflows/ruby.yml +30 -0
  4. data/.gitignore +6 -0
  5. data/ChangeLog.md +131 -1
  6. data/README.md +128 -0
  7. data/Rakefile +38 -1
  8. data/benchmarks.rb +8 -4
  9. data/ext/digest/Rakefile +46 -0
  10. data/ext/digest/compat/ruby.h +11 -0
  11. data/ext/digest/crc12_3gpp/crc12_3gpp.c +68 -0
  12. data/ext/digest/crc12_3gpp/crc12_3gpp.h +11 -0
  13. data/ext/digest/crc12_3gpp/crc12_3gpp_ext.c +27 -0
  14. data/ext/digest/crc12_3gpp/extconf.rb +7 -0
  15. data/ext/digest/crc15/crc15.c +54 -0
  16. data/ext/digest/crc15/crc15.h +11 -0
  17. data/ext/digest/crc15/crc15_ext.c +28 -0
  18. data/ext/digest/crc15/extconf.rb +7 -0
  19. data/ext/digest/crc16/crc16.c +70 -0
  20. data/ext/digest/crc16/crc16.h +11 -0
  21. data/ext/digest/crc16/crc16_ext.c +28 -0
  22. data/ext/digest/crc16/extconf.rb +7 -0
  23. data/ext/digest/crc16_ccitt/crc16_ccitt.c +70 -0
  24. data/ext/digest/crc16_ccitt/crc16_ccitt.h +8 -0
  25. data/ext/digest/crc16_ccitt/crc16_ccitt_ext.c +28 -0
  26. data/ext/digest/crc16_ccitt/extconf.rb +7 -0
  27. data/ext/digest/crc16_dnp/crc16_dnp.c +54 -0
  28. data/ext/digest/crc16_dnp/crc16_dnp.h +8 -0
  29. data/ext/digest/crc16_dnp/crc16_dnp_ext.c +28 -0
  30. data/ext/digest/crc16_dnp/extconf.rb +7 -0
  31. data/ext/digest/crc16_genibus/crc16_genibus.c +70 -0
  32. data/ext/digest/crc16_genibus/crc16_genibus.h +8 -0
  33. data/ext/digest/crc16_genibus/crc16_genibus_ext.c +28 -0
  34. data/ext/digest/crc16_genibus/extconf.rb +7 -0
  35. data/ext/digest/crc16_kermit/crc16_kermit.c +70 -0
  36. data/ext/digest/crc16_kermit/crc16_kermit.h +8 -0
  37. data/ext/digest/crc16_kermit/crc16_kermit_ext.c +28 -0
  38. data/ext/digest/crc16_kermit/extconf.rb +7 -0
  39. data/ext/digest/crc16_modbus/crc16_modbus.c +70 -0
  40. data/ext/digest/crc16_modbus/crc16_modbus.h +8 -0
  41. data/ext/digest/crc16_modbus/crc16_modbus_ext.c +28 -0
  42. data/ext/digest/crc16_modbus/extconf.rb +7 -0
  43. data/ext/digest/crc16_usb/crc16_usb.c +70 -0
  44. data/ext/digest/crc16_usb/crc16_usb.h +8 -0
  45. data/ext/digest/crc16_usb/crc16_usb_ext.c +28 -0
  46. data/ext/digest/crc16_usb/extconf.rb +7 -0
  47. data/ext/digest/crc16_x_25/crc16_x_25.c +70 -0
  48. data/ext/digest/crc16_x_25/crc16_x_25.h +8 -0
  49. data/ext/digest/crc16_x_25/crc16_x_25_ext.c +28 -0
  50. data/ext/digest/crc16_x_25/extconf.rb +7 -0
  51. data/ext/digest/crc16_xmodem/crc16_xmodem.c +70 -0
  52. data/ext/digest/crc16_xmodem/crc16_xmodem.h +8 -0
  53. data/ext/digest/crc16_xmodem/crc16_xmodem_ext.c +28 -0
  54. data/ext/digest/crc16_xmodem/extconf.rb +7 -0
  55. data/ext/digest/crc16_zmodem/crc16_zmodem.c +70 -0
  56. data/ext/digest/crc16_zmodem/crc16_zmodem.h +8 -0
  57. data/ext/digest/crc16_zmodem/crc16_zmodem_ext.c +28 -0
  58. data/ext/digest/crc16_zmodem/extconf.rb +7 -0
  59. data/ext/digest/crc24/crc24.c +70 -0
  60. data/ext/digest/crc24/crc24.h +11 -0
  61. data/ext/digest/crc24/crc24_ext.c +27 -0
  62. data/ext/digest/crc24/extconf.rb +7 -0
  63. data/ext/digest/crc32/crc32.c +69 -0
  64. data/ext/digest/crc32/crc32.h +11 -0
  65. data/ext/digest/crc32/crc32_ext.c +27 -0
  66. data/ext/digest/crc32/extconf.rb +7 -0
  67. data/ext/digest/crc32_bzip2/crc32_bzip2.c +70 -0
  68. data/ext/digest/crc32_bzip2/crc32_bzip2.h +8 -0
  69. data/ext/digest/crc32_bzip2/crc32_bzip2_ext.c +27 -0
  70. data/ext/digest/crc32_bzip2/extconf.rb +7 -0
  71. data/ext/digest/crc32_jam/crc32_jam.c +70 -0
  72. data/ext/digest/crc32_jam/crc32_jam.h +8 -0
  73. data/ext/digest/crc32_jam/crc32_jam_ext.c +27 -0
  74. data/ext/digest/crc32_jam/extconf.rb +7 -0
  75. data/ext/digest/crc32_mpeg/crc32_mpeg.c +70 -0
  76. data/ext/digest/crc32_mpeg/crc32_mpeg.h +8 -0
  77. data/ext/digest/crc32_mpeg/crc32_mpeg_ext.c +27 -0
  78. data/ext/digest/crc32_mpeg/extconf.rb +7 -0
  79. data/ext/digest/crc32_posix/crc32_posix.c +70 -0
  80. data/ext/digest/crc32_posix/crc32_posix.h +8 -0
  81. data/ext/digest/crc32_posix/crc32_posix_ext.c +27 -0
  82. data/ext/digest/crc32_posix/extconf.rb +7 -0
  83. data/ext/digest/crc32_xfer/crc32_xfer.c +70 -0
  84. data/ext/digest/crc32_xfer/crc32_xfer.h +8 -0
  85. data/ext/digest/crc32_xfer/crc32_xfer_ext.c +27 -0
  86. data/ext/digest/crc32_xfer/extconf.rb +7 -0
  87. data/ext/digest/crc32c/crc32c.c +70 -0
  88. data/ext/digest/crc32c/crc32c.h +8 -0
  89. data/ext/digest/crc32c/crc32c_ext.c +27 -0
  90. data/ext/digest/crc32c/extconf.rb +7 -0
  91. data/ext/digest/crc5/crc5.c +54 -0
  92. data/ext/digest/crc5/crc5.h +11 -0
  93. data/ext/digest/crc5/crc5_ext.c +27 -0
  94. data/ext/digest/crc5/extconf.rb +7 -0
  95. data/ext/digest/crc64/crc64.c +102 -0
  96. data/ext/digest/crc64/crc64.h +11 -0
  97. data/ext/digest/crc64/crc64_ext.c +27 -0
  98. data/ext/digest/crc64/extconf.rb +7 -0
  99. data/ext/digest/crc64_jones/crc64_jones.c +102 -0
  100. data/ext/digest/crc64_jones/crc64_jones.h +8 -0
  101. data/ext/digest/crc64_jones/crc64_jones_ext.c +27 -0
  102. data/ext/digest/crc64_jones/extconf.rb +7 -0
  103. data/ext/digest/crc64_xz/crc64_xz.c +102 -0
  104. data/ext/digest/crc64_xz/crc64_xz.h +8 -0
  105. data/ext/digest/crc64_xz/crc64_xz_ext.c +27 -0
  106. data/ext/digest/crc64_xz/extconf.rb +7 -0
  107. data/ext/digest/crc8/crc8.c +54 -0
  108. data/ext/digest/crc8/crc8.h +11 -0
  109. data/ext/digest/crc8/crc8_ext.c +27 -0
  110. data/ext/digest/crc8/extconf.rb +7 -0
  111. data/ext/digest/crc8_1wire/crc8_1wire.c +54 -0
  112. data/ext/digest/crc8_1wire/crc8_1wire.h +8 -0
  113. data/ext/digest/crc8_1wire/crc8_1wire_ext.c +27 -0
  114. data/ext/digest/crc8_1wire/extconf.rb +7 -0
  115. data/gemspec.yml +7 -1
  116. data/lib/digest/crc15.rb +4 -0
  117. data/lib/digest/crc16.rb +4 -0
  118. data/lib/digest/crc16_ccitt.rb +4 -0
  119. data/lib/digest/crc16_dnp.rb +4 -0
  120. data/lib/digest/crc16_genibus.rb +4 -0
  121. data/lib/digest/crc16_kermit.rb +4 -0
  122. data/lib/digest/crc16_modbus.rb +4 -0
  123. data/lib/digest/crc16_qt.rb +3 -59
  124. data/lib/digest/crc16_usb.rb +4 -0
  125. data/lib/digest/crc16_x_25.rb +4 -0
  126. data/lib/digest/crc16_xmodem.rb +4 -0
  127. data/lib/digest/crc16_zmodem.rb +4 -0
  128. data/lib/digest/crc24.rb +4 -0
  129. data/lib/digest/crc32.rb +5 -1
  130. data/lib/digest/crc32_bzip2.rb +4 -0
  131. data/lib/digest/crc32_mpeg.rb +4 -0
  132. data/lib/digest/crc32_posix.rb +4 -0
  133. data/lib/digest/crc32_xfer.rb +4 -0
  134. data/lib/digest/crc32c.rb +4 -0
  135. data/lib/digest/crc5.rb +4 -0
  136. data/lib/digest/crc64.rb +4 -0
  137. data/lib/digest/crc64_jones.rb +4 -0
  138. data/lib/digest/crc64_xz.rb +4 -0
  139. data/lib/digest/crc8.rb +4 -0
  140. data/lib/digest/crc8_1wire.rb +4 -0
  141. data/spec/crc16_qt_spec.rb +5 -5
  142. data/spec/integration/docker/Dockerfile.base +9 -0
  143. data/spec/integration/docker/Dockerfile.with-gcc +3 -0
  144. data/spec/integration/docker/Dockerfile.with-gcc-and-make +3 -0
  145. data/spec/integration/install_spec.rb +59 -0
  146. metadata +137 -5
  147. data/.travis.yml +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f92ef55b3e61da5d83aca365fabce146aaa938ff0ee7f380496f30b2909cd8c
4
- data.tar.gz: a34bfa0d5c6b86e29ee5cc27d157a8ea45596e03ffdd7d7d740eaeb9ccca8e6f
3
+ metadata.gz: f5e688a7da7f932c40ddbfc271ac0fada5ec85a5b98bcfec9040d15279bef8a2
4
+ data.tar.gz: 7f51652724f8b0e168d702e068a63e1b1ff7db080e2d6efd1b9930c57ac12c5b
5
5
  SHA512:
6
- metadata.gz: cafe8835843afd7873891d6a8c85ba294b8cb846a63641a273844aa50801071d77a92a6e1391e82b9921b199163ab87f9864885ba94f1efaf5a241448a9c0143
7
- data.tar.gz: 3787c83078142822c4d7ff198abbcd5a148061612079877ed8f4e4a3b828a4addb9484c4eb36beb417f30c570c336e1a708d7d9a3735342b3553f1d18e69fb8a
6
+ metadata.gz: 88e32eb6fe7fb27b4ff1e3bbbffbe1680a9b22f7a58a1021518601bc6944279fa82acf9303bd70e62cce7fd7f8b168e079153a9a00241130f9cec339305f5874
7
+ data.tar.gz: '093770c8846be1baa29522e3a15d35b114eb5836cd5ebc7f9fa64776330694e8a9111a429ba8c3e7d9885ae2a4093e73c9bccdefdc5974b1d4270795ed901e1a'
@@ -0,0 +1,26 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ tags: [ 'v0.*' ]
6
+ pull_request:
7
+ paths: [ 'ext/**' ]
8
+
9
+ jobs:
10
+ tests:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ name: Integration Testing
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Docker
18
+ uses: docker-practice/actions-setup-docker@master
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: 2.7
23
+ - name: Install dependencies
24
+ run: bundle install --jobs 4 --retry 3
25
+ - name: Run integration tests
26
+ run: bundle exec rake spec:integration
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ tests:
7
+ runs-on: ${{ matrix.os }}
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ os:
12
+ - ubuntu-latest
13
+ - macos-latest
14
+ ruby:
15
+ - 2.4
16
+ - 2.5
17
+ - 2.6
18
+ - 2.7
19
+ - jruby
20
+ name: OS ${{ matrix.os }} / Ruby ${{ matrix.ruby }}
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ - name: Install dependencies
28
+ run: bundle install --jobs 4 --retry 3
29
+ - name: Run tests
30
+ run: bundle exec rake spec
data/.gitignore CHANGED
@@ -3,3 +3,9 @@ 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
11
+ /spec/integration/docker/digest-crc.gem
@@ -1,3 +1,134 @@
1
+ ### 0.6.3 / 2020-12-19
2
+
3
+ * Broaden rake dependency to >= 12.0.0, < 14.0.0` for ruby 2.7, which includes
4
+ rake 13.x.
5
+
6
+ ### 0.6.2 / 2020-12-03
7
+
8
+ * Lower the rake dependency to `~> 12.0` for ruby 2.6.
9
+ * Fixed a bug in `ext/digest/Rakefile` which prevented digest-crc from being
10
+ installed on systems where C extensions could not be successfully compiled.
11
+ * Rake's `ruby` method, which in turn calls rake's `sh` method, raises
12
+ a `RuntimeError` exception when the ruby command fails, causing rake to
13
+ exit with an error code. Instead, rescue any `RuntimeError` exceptions and
14
+ fail gracefully.
15
+
16
+ ### 0.6.1 / 2020-07-02
17
+
18
+ * Fix installation issues under bundler by adding rake as an explicit dependency
19
+ (@rogerluan).
20
+
21
+ ### 0.6.0 / 2020-07-01
22
+
23
+ * Implement _optional_ C extensions for all CRC algorithms, resulting in an
24
+ average performance improvement of ~40x. Note, if for whatever reason the
25
+ C extensions cannot be compiled, they will be skipped and the pure-Ruby
26
+ CRC algorithms will be used instead. If the C extensions were successfully
27
+ compiled, then they will be loaded and override the pure-Ruby CRC methods with
28
+ the C equivalents.
29
+ * Alias {Digest::CRC16QT} to {Digest::CRC16X25}, since they are effectively the same (@dearblue).
30
+ * Fix {Digest::CRC32::WIDTH} (@dearblue).
31
+
32
+ #### pure-Ruby (ruby 2.7.1)
33
+
34
+ Loading Digest::CRC classes ...
35
+ Generating 1000 8Kb lengthed strings ...
36
+ Benchmarking Digest::CRC classes ...
37
+ user system total real
38
+ Digest::CRC1#update 0.412953 0.000000 0.412953 ( 0.414688)
39
+ Digest::CRC5#update 1.116375 0.000003 1.116378 ( 1.120741)
40
+ Digest::CRC8#update 0.994263 0.000013 0.994276 ( 1.001079)
41
+ Digest::CRC8_1Wire#update 0.974115 0.000004 0.974119 ( 0.978186)
42
+ Digest::CRC15#update 1.139402 0.000927 1.140329 ( 1.146608)
43
+ Digest::CRC16#update 0.967836 0.000000 0.967836 ( 0.971792)
44
+ Digest::CRC16CCITT#update 1.118851 0.000000 1.118851 ( 1.123217)
45
+ Digest::CRC16DNP#update 0.922211 0.000000 0.922211 ( 0.925739)
46
+ Digest::CRC16Genibus#update 1.120580 0.000000 1.120580 ( 1.124771)
47
+ Digest::CRC16Modbus#update 0.955612 0.000000 0.955612 ( 0.959463)
48
+ Digest::CRC16QT#update 8.153403 0.000012 8.153415 ( 8.189977)
49
+ Digest::CRC16USB#update 0.952557 0.000000 0.952557 ( 0.956145)
50
+ Digest::CRC16X25#update 0.962295 0.000000 0.962295 ( 0.970401)
51
+ Digest::CRC16XModem#update 1.120531 0.000000 1.120531 ( 1.124494)
52
+ Digest::CRC16ZModem#update 1.124226 0.000000 1.124226 ( 1.128632)
53
+ Digest::CRC24#update 1.126317 0.000000 1.126317 ( 1.130794)
54
+ Digest::CRC32#update 0.960015 0.000000 0.960015 ( 0.964803)
55
+ Digest::CRC32BZip2#update 1.128626 0.000000 1.128626 ( 1.133641)
56
+ Digest::CRC32c#update 0.964047 0.000000 0.964047 ( 0.967456)
57
+ Digest::CRC32Jam#update 0.959141 0.000972 0.960113 ( 0.967444)
58
+ Digest::CRC32MPEG#update 1.131119 0.000002 1.131121 ( 1.137440)
59
+ Digest::CRC32POSIX#update 1.126019 0.000000 1.126019 ( 1.130549)
60
+ Digest::CRC32XFER#update 1.116598 0.000000 1.116598 ( 1.120595)
61
+ Digest::CRC64#update 2.665880 0.000928 2.666808 ( 2.680942)
62
+ Digest::CRC64Jones#update 2.678003 0.000000 2.678003 ( 2.691390)
63
+ Digest::CRC64XZ#update 2.671395 0.000000 2.671395 ( 2.682684)
64
+
65
+ #### pure-Ruby (jruby 9.2.11.1)
66
+
67
+ Loading Digest::CRC classes ...
68
+ Generating 1000 8Kb lengthed strings ...
69
+ Benchmarking Digest::CRC classes ...
70
+ user system total real
71
+ Digest::CRC1#update 0.700000 0.070000 0.770000 ( 0.436112)
72
+ Digest::CRC5#update 1.930000 0.050000 1.980000 ( 1.084749)
73
+ Digest::CRC8#update 1.510000 0.060000 1.570000 ( 0.979123)
74
+ Digest::CRC8_1Wire#update 0.730000 0.030000 0.760000 ( 0.761309)
75
+ Digest::CRC15#update 1.760000 0.080000 1.840000 ( 1.061413)
76
+ Digest::CRC16#update 1.560000 0.030000 1.590000 ( 0.951273)
77
+ Digest::CRC16CCITT#update 1.700000 0.010000 1.710000 ( 1.046854)
78
+ Digest::CRC16DNP#update 1.490000 0.000000 1.490000 ( 0.902434)
79
+ Digest::CRC16Genibus#update 1.820000 0.020000 1.840000 ( 1.030269)
80
+ Digest::CRC16Modbus#update 0.740000 0.010000 0.750000 ( 0.738604)
81
+ Digest::CRC16QT#update 7.280000 0.040000 7.320000 ( 6.399987)
82
+ Digest::CRC16USB#update 0.930000 0.000000 0.930000 ( 0.801541)
83
+ Digest::CRC16X25#update 0.870000 0.000000 0.870000 ( 0.805130)
84
+ Digest::CRC16XModem#update 1.320000 0.010000 1.330000 ( 0.968956)
85
+ Digest::CRC16ZModem#update 1.300000 0.010000 1.310000 ( 0.928303)
86
+ Digest::CRC24#update 1.550000 0.020000 1.570000 ( 1.024450)
87
+ Digest::CRC32#update 1.260000 0.000000 1.260000 ( 0.913814)
88
+ Digest::CRC32BZip2#update 1.210000 0.010000 1.220000 ( 0.919086)
89
+ Digest::CRC32c#update 0.770000 0.010000 0.780000 ( 0.761726)
90
+ Digest::CRC32Jam#update 0.930000 0.000000 0.930000 ( 0.800468)
91
+ Digest::CRC32MPEG#update 1.240000 0.010000 1.250000 ( 0.933962)
92
+ Digest::CRC32POSIX#update 1.290000 0.010000 1.300000 ( 0.925254)
93
+ Digest::CRC32XFER#update 1.270000 0.000000 1.270000 ( 0.920521)
94
+ Digest::CRC64#update 3.480000 0.020000 3.500000 ( 2.883794)
95
+ Digest::CRC64Jones#update 2.740000 0.000000 2.740000 ( 2.738251)
96
+ Digest::CRC64XZ#update 2.780000 0.010000 2.790000 ( 2.715833)
97
+
98
+
99
+ #### C extensions (ruby 2.7.1)
100
+
101
+ Loading Digest::CRC classes ...
102
+ Generating 1000 8Kb lengthed strings ...
103
+ Benchmarking Digest::CRC classes ...
104
+ user system total real
105
+ Digest::CRC1#update 0.407438 0.000000 0.407438 ( 0.410495)
106
+ Digest::CRC5#update 0.022873 0.000000 0.022873 ( 0.023796)
107
+ Digest::CRC8#update 0.020129 0.000000 0.020129 ( 0.020887)
108
+ Digest::CRC8_1Wire#update 0.020106 0.000000 0.020106 ( 0.020897)
109
+ Digest::CRC15#update 0.028765 0.000003 0.028768 ( 0.029549)
110
+ Digest::CRC16#update 0.022176 0.000856 0.023032 ( 0.023153)
111
+ Digest::CRC16CCITT#update 0.028570 0.000000 0.028570 ( 0.028691)
112
+ Digest::CRC16DNP#update 0.023240 0.000001 0.023241 ( 0.024008)
113
+ Digest::CRC16Genibus#update 0.028692 0.000000 0.028692 ( 0.029575)
114
+ Digest::CRC16Modbus#update 0.023928 0.000000 0.023928 ( 0.024859)
115
+ Digest::CRC16QT#update 7.965822 0.000968 7.966790 ( 8.001781)
116
+ Digest::CRC16USB#update 0.023448 0.000001 0.023449 ( 0.024420)
117
+ Digest::CRC16X25#update 0.023061 0.000000 0.023061 ( 0.023861)
118
+ Digest::CRC16XModem#update 0.029407 0.000000 0.029407 ( 0.030583)
119
+ Digest::CRC16ZModem#update 0.029522 0.000000 0.029522 ( 0.030438)
120
+ Digest::CRC24#update 0.029528 0.000000 0.029528 ( 0.030504)
121
+ Digest::CRC32#update 0.023306 0.000000 0.023306 ( 0.024278)
122
+ Digest::CRC32BZip2#update 0.026346 0.000000 0.026346 ( 0.027293)
123
+ Digest::CRC32c#update 0.023525 0.000000 0.023525 ( 0.024489)
124
+ Digest::CRC32Jam#update 0.023348 0.000000 0.023348 ( 0.023477)
125
+ Digest::CRC32MPEG#update 0.026287 0.000000 0.026287 ( 0.027394)
126
+ Digest::CRC32POSIX#update 0.026063 0.000000 0.026063 ( 0.026986)
127
+ Digest::CRC32XFER#update 0.026374 0.000000 0.026374 ( 0.027314)
128
+ Digest::CRC64#update 0.023523 0.000000 0.023523 ( 0.024484)
129
+ Digest::CRC64Jones#update 0.023479 0.000000 0.023479 ( 0.024432)
130
+ Digest::CRC64XZ#update 0.024146 0.000000 0.024146 ( 0.025129)
131
+
1
132
  ### 0.5.1 / 2020-03-03
2
133
 
3
134
  * Fixed XOR logic in {Digest::CRC16Genibus}.
@@ -63,4 +194,3 @@
63
194
  * CRC32
64
195
  * CRC32 Mpeg
65
196
  * 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
 
@@ -51,6 +54,24 @@ module.
51
54
  gem install digest-crc
52
55
  ```
53
56
 
57
+ **Note:** to enable the C extensions ensure that you are using CRuby and have
58
+ a C compiler (`gcc` or `clang`) and `make` installed, _before_ installing
59
+ digest-crc.
60
+
61
+ * Debian / Ubuntu:
62
+
63
+ $ sudo apt install gcc make
64
+
65
+ * RedHat / Fedora:
66
+
67
+ $ sudo dnf install gcc make
68
+
69
+ * Alpine Linux:
70
+
71
+ $ apk add build-base
72
+
73
+ * macOS: install XCode
74
+
54
75
  ## Examples
55
76
 
56
77
  Calculate a CRC32:
@@ -116,6 +137,113 @@ module Digest
116
137
  end
117
138
  ```
118
139
 
140
+ ## Benchmarks
141
+
142
+ ### Pure Ruby (ruby 2.7.1)
143
+
144
+ $ bundle exec rake clean
145
+ $ bundle exec ./benchmarks.rb
146
+ Loading Digest::CRC classes ...
147
+ Generating 1000 8Kb lengthed strings ...
148
+ Benchmarking Digest::CRC classes ...
149
+ user system total real
150
+ Digest::CRC1#update 0.349756 0.000002 0.349758 ( 0.351427)
151
+ Digest::CRC5#update 1.175206 0.000049 1.175255 ( 1.180975)
152
+ Digest::CRC8#update 1.023536 0.000015 1.023551 ( 1.029017)
153
+ Digest::CRC8_1Wire#update 1.012156 0.000000 1.012156 ( 1.017342)
154
+ Digest::CRC15#update 1.187286 0.000005 1.187291 ( 1.193634)
155
+ Digest::CRC16#update 0.998527 0.000013 0.998540 ( 1.003940)
156
+ Digest::CRC16CCITT#update 1.179864 0.000005 1.179869 ( 1.186134)
157
+ Digest::CRC16DNP#update 1.018969 0.000003 1.018972 ( 1.025248)
158
+ Digest::CRC16Genibus#update 1.196754 0.000065 1.196819 ( 1.203605)
159
+ Digest::CRC16Modbus#update 1.007367 0.000000 1.007367 ( 1.012325)
160
+ Digest::CRC16X25#update 1.044127 0.000000 1.044127 ( 1.052010)
161
+ Digest::CRC16USB#update 1.012804 0.000000 1.012804 ( 1.018324)
162
+ Digest::CRC16X25#update 1.009694 0.000000 1.009694 ( 1.015890)
163
+ Digest::CRC16XModem#update 1.210814 0.000000 1.210814 ( 1.217951)
164
+ Digest::CRC16ZModem#update 1.175239 0.000000 1.175239 ( 1.181395)
165
+ Digest::CRC24#update 1.207431 0.000000 1.207431 ( 1.213373)
166
+ Digest::CRC32#update 1.012334 0.000000 1.012334 ( 1.017671)
167
+ Digest::CRC32BZip2#update 1.190351 0.000000 1.190351 ( 1.196567)
168
+ Digest::CRC32c#update 1.021147 0.000000 1.021147 ( 1.027035)
169
+ Digest::CRC32Jam#update 1.002365 0.000000 1.002365 ( 1.007202)
170
+ Digest::CRC32MPEG#update 1.161925 0.000000 1.161925 ( 1.168058)
171
+ Digest::CRC32POSIX#update 1.191860 0.000967 1.192827 ( 1.198722)
172
+ Digest::CRC32XFER#update 1.217692 0.000000 1.217692 ( 1.224075)
173
+ Digest::CRC64#update 3.084106 0.000000 3.084106 ( 3.106840)
174
+ Digest::CRC64Jones#update 3.016687 0.000000 3.016687 ( 3.038963)
175
+ Digest::CRC64XZ#update 3.019690 0.000000 3.019690 ( 3.040971)
176
+
177
+ ### C extensions (ruby 2.7.1)
178
+
179
+ $ bundle exec rake build:c_exts
180
+ ...
181
+ $ bundle exec ./benchmarks.rb
182
+ Loading Digest::CRC classes ...
183
+ Generating 1000 8Kb lengthed strings ...
184
+ Benchmarking Digest::CRC classes ...
185
+ user system total real
186
+ Digest::CRC1#update 0.356025 0.000016 0.356041 ( 0.365345)
187
+ Digest::CRC5#update 0.023957 0.000001 0.023958 ( 0.024835)
188
+ Digest::CRC8#update 0.021254 0.000007 0.021261 ( 0.024647)
189
+ Digest::CRC8_1Wire#update 0.039129 0.000000 0.039129 ( 0.042417)
190
+ Digest::CRC15#update 0.030285 0.000000 0.030285 ( 0.030560)
191
+ Digest::CRC16#update 0.023003 0.000000 0.023003 ( 0.023267)
192
+ Digest::CRC16CCITT#update 0.028207 0.000000 0.028207 ( 0.028467)
193
+ Digest::CRC16DNP#update 0.022861 0.000000 0.022861 ( 0.023111)
194
+ Digest::CRC16Genibus#update 0.028041 0.000000 0.028041 ( 0.028359)
195
+ Digest::CRC16Modbus#update 0.022931 0.000009 0.022940 ( 0.023560)
196
+ Digest::CRC16X25#update 0.022808 0.000000 0.022808 ( 0.023054)
197
+ Digest::CRC16USB#update 0.022258 0.000882 0.023140 ( 0.023418)
198
+ Digest::CRC16X25#update 0.022816 0.000000 0.022816 ( 0.023084)
199
+ Digest::CRC16XModem#update 0.027984 0.000000 0.027984 ( 0.028269)
200
+ Digest::CRC16ZModem#update 0.027968 0.000000 0.027968 ( 0.028214)
201
+ Digest::CRC24#update 0.028426 0.000000 0.028426 ( 0.028687)
202
+ Digest::CRC32#update 0.022805 0.000000 0.022805 ( 0.023043)
203
+ Digest::CRC32BZip2#update 0.025519 0.000000 0.025519 ( 0.025797)
204
+ Digest::CRC32c#update 0.022807 0.000000 0.022807 ( 0.023069)
205
+ Digest::CRC32Jam#update 0.023006 0.000000 0.023006 ( 0.023231)
206
+ Digest::CRC32MPEG#update 0.025536 0.000000 0.025536 ( 0.025861)
207
+ Digest::CRC32POSIX#update 0.025557 0.000000 0.025557 ( 0.025841)
208
+ Digest::CRC32XFER#update 0.025310 0.000000 0.025310 ( 0.025599)
209
+ Digest::CRC64#update 0.023182 0.000000 0.023182 ( 0.023421)
210
+ Digest::CRC64Jones#update 0.022916 0.000000 0.022916 ( 0.023139)
211
+ Digest::CRC64XZ#update 0.022879 0.000000 0.022879 ( 0.023131)
212
+
213
+ ### Pure Ruby (jruby 9.2.12.0)
214
+
215
+ $ bundle exec ./benchmarks.rb
216
+ Loading Digest::CRC classes ...
217
+ Generating 1000 8Kb lengthed strings ...
218
+ Benchmarking Digest::CRC classes ...
219
+ user system total real
220
+ Digest::CRC1#update 1.030000 0.090000 1.120000 ( 0.511189)
221
+ Digest::CRC5#update 1.620000 0.060000 1.680000 ( 1.096031)
222
+ Digest::CRC8#update 1.560000 0.070000 1.630000 ( 1.083921)
223
+ Digest::CRC8_1Wire#update 0.930000 0.040000 0.970000 ( 0.927024)
224
+ Digest::CRC15#update 1.590000 0.070000 1.660000 ( 1.132566)
225
+ Digest::CRC16#update 1.650000 0.060000 1.710000 ( 1.074508)
226
+ Digest::CRC16CCITT#update 1.610000 0.060000 1.670000 ( 1.190860)
227
+ Digest::CRC16DNP#update 1.270000 0.010000 1.280000 ( 0.938132)
228
+ Digest::CRC16Genibus#update 1.620000 0.030000 1.650000 ( 1.148556)
229
+ Digest::CRC16Modbus#update 1.070000 0.020000 1.090000 ( 0.881455)
230
+ Digest::CRC16X25#update 1.110000 0.010000 1.120000 ( 0.945366)
231
+ Digest::CRC16USB#update 1.140000 0.000000 1.140000 ( 0.984367)
232
+ Digest::CRC16X25#update 0.920000 0.010000 0.930000 ( 0.872541)
233
+ Digest::CRC16XModem#update 1.530000 0.010000 1.540000 ( 1.092838)
234
+ Digest::CRC16ZModem#update 1.720000 0.010000 1.730000 ( 1.164787)
235
+ Digest::CRC24#update 1.810000 0.020000 1.830000 ( 1.084953)
236
+ Digest::CRC32#update 1.590000 0.010000 1.600000 ( 1.105553)
237
+ Digest::CRC32BZip2#update 1.520000 0.010000 1.530000 ( 1.070839)
238
+ Digest::CRC32c#update 0.960000 0.010000 0.970000 ( 0.881989)
239
+ Digest::CRC32Jam#update 1.030000 0.010000 1.040000 ( 0.907208)
240
+ Digest::CRC32MPEG#update 1.420000 0.010000 1.430000 ( 0.994035)
241
+ Digest::CRC32POSIX#update 1.530000 0.020000 1.550000 ( 1.106366)
242
+ Digest::CRC32XFER#update 1.650000 0.010000 1.660000 ( 1.097647)
243
+ Digest::CRC64#update 3.440000 0.030000 3.470000 ( 2.771806)
244
+ Digest::CRC64Jones#update 2.630000 0.010000 2.640000 ( 2.628016)
245
+ Digest::CRC64XZ#update 3.200000 0.020000 3.220000 ( 2.913442)
246
+
119
247
  ## Thanks
120
248
 
121
249
  Special thanks go out to the [pycrc](http://www.tty1.net/pycrc/) library
data/Rakefile CHANGED
@@ -10,8 +10,45 @@ 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
+
26
+ file 'spec/integration/docker/digest-crc.gem' do |t|
27
+ sh "gem build -o #{t.name} digest-crc.gemspec"
28
+ end
29
+
13
30
  require 'rspec/core/rake_task'
14
- RSpec::Core::RakeTask.new
31
+ namespace :spec do
32
+ RSpec::Core::RakeTask.new(:pure) do |t|
33
+ t.exclude_pattern = 'spec/integration/*_spec.rb'
34
+ end
35
+ task :pure => :clean
36
+
37
+ if RUBY_ENGINE == 'ruby'
38
+ RSpec::Core::RakeTask.new(:c_exts) do |t|
39
+ t.exclude_pattern = 'spec/integration/*_spec.rb'
40
+ end
41
+ task :c_exts => 'build:c_exts'
42
+ end
43
+
44
+ RSpec::Core::RakeTask.new(:integration) do |t|
45
+ t.pattern = 'spec/integration/*_spec.rb'
46
+ end
47
+ end
48
+
49
+ task :spec => 'spec:pure'
50
+ task :spec => 'spec:c_exts' if RUBY_ENGINE == 'ruby'
51
+
15
52
  task :test => :spec
16
53
  task :default => :spec
17
54
 
@@ -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,46 @@
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
+ CRCS = Dir['crc*']
17
+ DLEXT = MakeMakefile::CONFIG['DLEXT']
18
+
19
+ CRCS.each do |crc|
20
+ crc_ext = "#{crc}_ext"
21
+
22
+ file "#{crc}/Makefile" => "#{crc}/extconf.rb" do
23
+ Dir.chdir(crc) do
24
+ begin
25
+ ruby '-S', 'extconf.rb'
26
+ rescue
27
+ fail_gracefully "extconf.rb failed"
28
+ end
29
+ end
30
+ end
31
+
32
+ crc_ext_lib = "#{crc}_ext.#{DLEXT}"
33
+
34
+ file "#{crc}/#{crc_ext_lib}" => "#{crc}/Makefile" do
35
+ Dir.chdir(crc) do
36
+ begin
37
+ sh 'make', 'clean'
38
+ sh 'make'
39
+ rescue
40
+ fail_gracefully "Unable to build C extensions"
41
+ end
42
+ end
43
+ end
44
+
45
+ task :default => "#{crc}/#{crc_ext_lib}"
46
+ end