hexdump 0.3.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -6
  3. data/.gitignore +1 -0
  4. data/.yardopts +1 -1
  5. data/ChangeLog.md +79 -6
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +1 -1
  8. data/README.md +500 -137
  9. data/benchmark.rb +29 -22
  10. data/gemspec.yml +2 -1
  11. data/hexdump.gemspec +1 -4
  12. data/lib/hexdump/chars.rb +46 -0
  13. data/lib/hexdump/core_ext/file.rb +68 -6
  14. data/lib/hexdump/core_ext/io.rb +2 -2
  15. data/lib/hexdump/core_ext/kernel.rb +5 -0
  16. data/lib/hexdump/core_ext/string.rb +2 -2
  17. data/lib/hexdump/core_ext/string_io.rb +2 -2
  18. data/lib/hexdump/core_ext.rb +5 -4
  19. data/lib/hexdump/format_string.rb +43 -0
  20. data/lib/hexdump/hexdump.rb +766 -75
  21. data/lib/hexdump/mixin.rb +192 -0
  22. data/lib/hexdump/module_methods.rb +132 -0
  23. data/lib/hexdump/numeric/binary.rb +55 -0
  24. data/lib/hexdump/numeric/char_or_int.rb +95 -0
  25. data/lib/hexdump/numeric/decimal.rb +56 -0
  26. data/lib/hexdump/numeric/exceptions.rb +11 -0
  27. data/lib/hexdump/numeric/hexadecimal.rb +59 -0
  28. data/lib/hexdump/numeric/octal.rb +55 -0
  29. data/lib/hexdump/numeric.rb +5 -0
  30. data/lib/hexdump/reader.rb +313 -0
  31. data/lib/hexdump/theme/ansi.rb +82 -0
  32. data/lib/hexdump/theme/rule.rb +159 -0
  33. data/lib/hexdump/theme.rb +61 -0
  34. data/lib/hexdump/type.rb +233 -0
  35. data/lib/hexdump/types.rb +108 -0
  36. data/lib/hexdump/version.rb +1 -1
  37. data/lib/hexdump.rb +14 -3
  38. data/spec/chars_spec.rb +76 -0
  39. data/spec/core_ext_spec.rb +10 -6
  40. data/spec/format_string_spec.rb +22 -0
  41. data/spec/hexdump_class_spec.rb +1708 -0
  42. data/spec/hexdump_module_spec.rb +23 -0
  43. data/spec/mixin_spec.rb +37 -0
  44. data/spec/numeric/binary_spec.rb +239 -0
  45. data/spec/numeric/char_or_int_spec.rb +210 -0
  46. data/spec/numeric/decimal_spec.rb +317 -0
  47. data/spec/numeric/hexadecimal_spec.rb +320 -0
  48. data/spec/numeric/octal_spec.rb +239 -0
  49. data/spec/reader_spec.rb +866 -0
  50. data/spec/spec_helper.rb +2 -0
  51. data/spec/theme/ansi_spec.rb +242 -0
  52. data/spec/theme/rule_spec.rb +199 -0
  53. data/spec/theme_spec.rb +94 -0
  54. data/spec/type_spec.rb +317 -0
  55. data/spec/types_spec.rb +904 -0
  56. metadata +42 -12
  57. data/.gemtest +0 -0
  58. data/lib/hexdump/dumper.rb +0 -419
  59. data/lib/hexdump/extensions.rb +0 -2
  60. data/spec/dumper_spec.rb +0 -329
  61. data/spec/hexdump_spec.rb +0 -30
data/README.md CHANGED
@@ -1,164 +1,527 @@
1
1
  # hexdump.rb
2
2
 
3
3
  [![CI](https://github.com/postmodern/hexdump.rb/actions/workflows/ruby.yml/badge.svg)](https://github.com/postmodern/hexdump.rb/actions/workflows/ruby.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/hexdump.svg)](https://badge.fury.io/rb/hexdump)
4
5
 
5
6
  * [Source](https://github.com/postmodern/hexdump.rb)
6
7
  * [Issues](https://github.com/postmodern/hexdump.rb/issues)
7
- * [Documentation](http://rubydoc.info/gems/hexdump/frames)
8
- * [Email](mailto:postmodern.mod3 at gmail.com)
8
+ * [Documentation](https://rubydoc.info/gems/hexdump)
9
9
 
10
10
  ## Description
11
11
 
12
- Simple and Fast hexdumping for Ruby.
12
+ Fully Featured and Fast hexdumping for Ruby.
13
13
 
14
14
  ## Features
15
15
 
16
+ * Supports printing ASCII, hexadecimal, decimal, octal and binary bytes.
17
+ * Supports hexdumping bytes, characters, signed/unsigned integers,
18
+ floating-point numbers, and in little/big/network endian byte orders:
19
+ * `char` - signed 8bit ASCII character
20
+ * `uchar` - unsigned 8bit ASCII character
21
+ * `int8` - signed 8bit integer
22
+ * `uin8` / `byte` - unsigned 8bit integer (default)
23
+ * `int16` / `short` - signed 16bit integer
24
+ * `int16_le` / `short_le` - signed 16bit integer (little endian)
25
+ * `int16_be` / `short_be` - signed 16bit integer (big endian)
26
+ * `int16_ne` / `short_ne` - signed 16bit integer (network endian)
27
+ * `uint16` / `ushort` - unsigned 16bit integer
28
+ * `uint16_le` / `ushort_le` - unsigned 16bit integer (little endian)
29
+ * `uint16_be` / `ushort_be` - unsigned 16bit integer (big endian)
30
+ * `uint16_ne` / `ushort_ne` - unsigned 16bit integer (network endian)
31
+ * `int32` / `int` - signed 32bit integer
32
+ * `int32_le` / `int_le` - signed 32bit integer (little endian)
33
+ * `int32_be` / `int_be` - signed 32bit integer (big endian)
34
+ * `int32_ne` / `int_ne` - signed 32bit integer (network endian)
35
+ * `uint32` / `uint` / - unsigned 32bit integer
36
+ * `uint32_le` / `uint_le` - unsigned 32bit integer
37
+ (little endian)
38
+ * `uint32_be` / `uint_be` - unsigned 32bit integer (big endian)
39
+ * `uint32_ne` / `uint_ne` - unsigned 32bit integer
40
+ (network endian)
41
+ * `int64` / `long` / `long_long` - signed 64bit integer
42
+ * `int64_le` / `long_le` / `long_long_le` - signed 64bit integer
43
+ (little endian)
44
+ * `int64_be` / `long_be` / `long_long_be` - signed 64bit integer (big endian)
45
+ * `int64_ne` / `long_ne` / `long_long_ne` - signed 64bit integer
46
+ (network endian)
47
+ * `uint64` `ulong` / `ulong_long` - unsigned 64bit integer
48
+ * `uint64_le` / `ulong_le` / `ulong_long_le` - unsigned 64bit integer
49
+ (little endian)
50
+ * `uint64_be` / `ulong_be` / `ulong_long_be` - unsigned 64bit integer
51
+ (big endian)
52
+ * `uint64_ne` / `ulong_ne` / `ulong_long_ne` - unsigned 64bit integer
53
+ (network endian)
54
+ * `float` - single precision 32bit floating-point number
55
+ * `float_le` - single precision 32bit floating-point number (little endian)
56
+ * `float_be` - single precision 32bit floating-point number (big endian)
57
+ * `float_ne` - single precision 32bit floating-point number (network endian)
58
+ * `double` - double precision 64bit floating-point number
59
+ * `double_le` - double precision 64bit floating-point number (little endian)
60
+ * `double_be` - double precision 64bit floating-point number (big endian)
61
+ * `double_ne` - double precision 64bit floating-point number (network endian)
62
+ * Supports optionally skipping N bytes or reading at most N bytes of data.
63
+ * Supports optional zero-padding of the data.
64
+ * Supports omitting repeating rows with a `*`.
65
+ * Supports grouping columns together like GNU `hexdump -C`.
66
+ * Supports grouping characters together to align with the type's size.
67
+ * Supports displaying characters inline like GNU `hexdump -c`.
68
+ * Supports displaying UTF-8 characters or other character encodings.
69
+ * Supports ANSI styling and highlighting.
16
70
  * Can hexdump any Object supporting the `each_byte` method.
17
71
  * Can send the hexdump output to any Object supporting the `<<` method.
18
- * Can yield each line of hexdump, instead of printing the output.
19
- * Supports printing ASCII, hexadecimal, decimal, octal and binary bytes.
20
- * Supports hexdumping bytes (8bit), words (16bit), double-words (32bit), and
21
- quad-words (64bit).
22
- * Supports Little Endian and Big Endian modes.
23
72
  * Makes {String}, {StringIO}, {IO}, {File} objects hexdumpable.
24
73
  * Fast-ish.
25
74
 
26
- ## Examples
75
+ ## Requirements
76
+
77
+ * [Ruby] >= 2.0.0
27
78
 
28
- require 'hexdump'
29
-
30
- data = "hello\x00"
31
-
32
- Hexdump.dump(data)
33
- # 00000000 68 65 6c 6c 6f 00 |hello.|
34
- # 00000006
35
-
36
- data.hexdump
37
- # 00000000 68 65 6c 6c 6f 00 |hello.|
38
- # 00000006
39
-
40
- File.open('dump.txt','w') do |file|
41
- data.hexdump(:output => file)
42
- end
43
-
44
- # iterate over the hexdump lines
45
- data.hexdump do |index,hex,printable|
46
- index # => 0
47
- hex # => ["68", "65", "6c", "6c", "6f", "00"]
48
- printable # => ["h", "e", "l", "l", "o", "."]
49
- end
50
- # => 6
51
-
52
- # configure the width of the hexdump
53
- Hexdump.dump('A' * 30, width: 10)
54
- # 00000000 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAA|
55
- # 0000000a 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAA|
56
- # 00000014 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAA|
57
- # 0000001e
58
-
59
- Hexdump.dump(data, ascii: true)
60
- # 00000000 h e l l o 00 |hello.|
61
- # 00000006
62
-
63
- Hexdump.dump(data, base: 16)
64
- # 00000000 68 65 6c 6c 6f 00 |hello.|
65
- # 00000006
66
-
67
- Hexdump.dump(data, base: :decimal)
68
- # 00000000 104 101 108 108 111 0 |hello.|
69
- # 00000006
70
-
71
- Hexdump.dump(data, base: :octal)
72
- # 00000000 0150 0145 0154 0154 0157 0000 |hello.|
73
- # 00000006
74
-
75
- Hexdump.dump(data, base: :binary)
76
- # 00000000 01101000 01100101 01101100 01101100 01101111 00000000 |hello.|
77
- # 00000006
78
-
79
- ("ABC" * 10).hexdump(word_size: 2)
80
- # 00000000 4241 4143 4342 4241 4143 4342 4241 4143 |䉁䅃䍂䉁䅃䍂䉁䅃|
81
- # 00000010 4342 4241 4143 4342 4241 4143 4342 |䍂䉁䅃䍂䉁䅃䍂|
82
- # 0000001e
79
+ [Ruby]: https://www.ruby-lang.org/
83
80
 
84
81
  ## Install
85
82
 
86
- $ gem install hexdump
83
+ ```shell
84
+ $ gem install hexdump
85
+ ```
86
+
87
+ ### gemspec
88
+
89
+ ```ruby
90
+ gem.add_dependency 'hexdump', '~> 1.0'
91
+ ```
92
+
93
+ ### Gemfile
94
+
95
+ ```ruby
96
+ gem 'hexdump', '~> 1.0'
97
+ ```
98
+
99
+ ## Examples
100
+
101
+ ```ruby
102
+ require 'hexdump'
103
+
104
+ Hexdump.hexdump("hello\0")
105
+ # 00000000 68 65 6c 6c 6f 00 |hello.|
106
+ # 00000006
107
+ ```
108
+
109
+ ### Core Extensions
110
+
111
+ ```ruby
112
+ "hello\0".hexdump
113
+ # 00000000 68 65 6c 6c 6f 00 |hello.|
114
+ # 00000006
115
+ ```
116
+
117
+ ```ruby
118
+ File.hexdump("/bin/ls")
119
+ # ...
120
+ ```
121
+
122
+ ### Output (file)
123
+
124
+ ```ruby
125
+ File.open('dump.txt','w') do |file|
126
+ data.hexdump(output: file)
127
+ end
128
+ ```
129
+
130
+ ### UTF-8
131
+
132
+ ```ruby
133
+ Hexdump.hexdump("\u8000" * 8, encoding: :utf8)
134
+ # 00000000 e8 80 80 e8 80 80 e8 80 80 e8 80 80 e8 80 80 e8 |耀耀耀耀耀.|
135
+ # 00000010 80 80 e8 80 80 e8 80 80 |..耀耀|
136
+ # 00000018
137
+ ```
138
+
139
+ ### Columns
140
+
141
+ ```ruby
142
+ Hexdump.hexdump('A' * 30, columns: 10)
143
+ # 00000000 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAA|
144
+ # *
145
+ # 0000001e
146
+ ```
147
+
148
+ ### Repeating Columns
149
+
150
+ ```ruby
151
+ Hexdump.hexdump('A' * 30, columns: 10, repeating: true)
152
+ # 00000000 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAA|
153
+ # 0000000a 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAA|
154
+ # 00000014 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAA|
155
+ # 0000001e
156
+ ```
157
+
158
+ ### Grouping Columns
159
+
160
+ ```ruby
161
+ Hexdump.hexdump("ABCD" * 8, columns: 16, group_columns: 4, repeating: true)
162
+ # 00000000 41 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 |ABCDABCDABCDABCD|
163
+ # 00000010 41 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 |ABCDABCDABCDABCD|
164
+ # 00000020
165
+ ```
166
+
167
+ ### Grouping Chars
168
+
169
+ ```ruby
170
+ Hexdump.hexdump("ABCD" * 8, group_chars: 4)
171
+ # 00000000 41 42 43 44 41 42 43 44 41 42 43 44 41 42 43 44 |ABCD|ABCD|ABCD|ABCD|
172
+ # *
173
+ # 00000020
174
+ ```
175
+
176
+ ### Grouping UTF-8 Chars
177
+
178
+ ```ruby
179
+ Hexdump.hexdump("\u8000" * 8, group_chars: 4, encoding: :utf8)
180
+ # 00000000 e8 80 80 e8 80 80 e8 80 80 e8 80 80 e8 80 80 e8 |耀.|...|.耀|耀.|
181
+ # 00000010 80 80 e8 80 80 e8 80 80 |...|.耀|
182
+ # 00000018
183
+ ```
184
+
185
+ ### Disable Chars
186
+
187
+ ```ruby
188
+ Hexdump.hexdump('A' * 30, chars_column: false)
189
+ 00000000 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41
190
+ 00000010 41 41 41 41 41 41 41 41 41 41 41 41 41 41
191
+ 0000001e
192
+ ```
193
+
194
+ ### Hexadecimal
195
+
196
+ ```ruby
197
+ Hexdump.hexdump("hello\0", base: 16)
198
+ # 00000000 68 65 6c 6c 6f 00 |hello.|
199
+ # 00000006
200
+ ```
201
+
202
+ ### Decimal
203
+
204
+ ```ruby
205
+ Hexdump.hexdump("hello\0", base: 10)
206
+ # 00000000 104 101 108 108 111 0 |hello.|
207
+ # 00000006
208
+ ```
209
+
210
+ ### Octal
211
+
212
+ ```ruby
213
+ Hexdump.hexdump("hello\0", base: 8)
214
+ # 00000000 0150 0145 0154 0154 0157 0000 |hello.|
215
+ # 00000006
216
+ ```
217
+
218
+ ### Binary
219
+
220
+ ```ruby
221
+ Hexdump.hexdump("hello\0", base: 2)
222
+ # 00000000 01101000 01100101 01101100 01101100 01101111 00000000 |hello.|
223
+ # 00000006
224
+ ```
225
+
226
+ ### UInt Type
227
+
228
+ ```ruby
229
+ Hexdump.hexdump("ABCD" * 7, type: :uint32)
230
+ # 00000000 44434241 44434241 44434241 44434241 |ABCDABCDABCDABCD|
231
+ # 00000010 44434241 44434241 44434241 |ABCDABCDABCD|
232
+ # 0000001c
233
+ ```
234
+
235
+ ### Little-endian
236
+
237
+ ```ruby
238
+ Hexdump.hexdump("ABCD" * 7, type: :uint32_le)
239
+ # 00000000 44434241 44434241 44434241 44434241 |ABCDABCDABCDABCD|
240
+ # 00000010 44434241 44434241 44434241 |ABCDABCDABCD|
241
+ # 0000001c
242
+ ```
243
+
244
+ ### Big-endian
245
+
246
+ ```ruby
247
+ Hexdump.hexdump("ABCD" * 7, type: :uint32_be)
248
+ # 00000000 41424344 41424344 41424344 41424344 |ABCDABCDABCDABCD|
249
+ # 00000010 41424344 41424344 41424344 |ABCDABCDABCD|
250
+ # 0000001c
251
+ ```
252
+
253
+ ### Int Type
254
+
255
+ ```ruby
256
+ Hexdump.hexdump([65535, -1].pack("LL"), type: :int32, base: 10)
257
+ # 00000000 65535 -1 |........|
258
+ # 00000008
259
+ ```
260
+
261
+ ### Char Type
262
+
263
+ ```ruby
264
+ Hexdump.hexdump("hello\0", type: :char)
265
+ # 00000000 h e l l o \0 |hello.|
266
+ # 00000006
267
+ ```
268
+
269
+ ### Float Type
270
+
271
+ ```ruby
272
+ Hexdump.hexdump([0.0, 1.0, -1.0, Float::NAN].pack('EEEE'), type: :float64_le)
273
+ # 00000000 0.000000e+00 1.000000e+00 |...............?|
274
+ # 00000010 -1.000000e+00 NaN |................|
275
+ # 00000020
276
+ ```
277
+
278
+ ### Skipping Data
279
+
280
+ ```ruby
281
+ Hexdump.hexdump("GARBAGEabc123", offset: 7)
282
+ # 00000007 61 62 63 31 32 33 |abc123|
283
+ # 0000000d
284
+ ```
285
+
286
+ ### Zero-padding
287
+
288
+ ```ruby
289
+ Hexdump.hexdump(("ABCD" * 4) + "AB", type: :uint32_be, zero_pad: true)
290
+ # 00000000 41424344 41424344 41424344 41424344 |ABCDABCDABCDABCD|
291
+ # 00000010 41420000 |AB..|
292
+ # 00000014
293
+ ```
294
+
295
+ ### ANSI Styling
296
+
297
+ ```ruby
298
+ Hexdump.hexdump("ABCD", style: {index: :white, numeric: :green, chars: :cyan})
299
+ ```
300
+
301
+ ### ANSI Highlighting
302
+
303
+ ```ruby
304
+ Hexdump.hexdump((0..255).map(&:chr).join, highlights: {
305
+ index: {/00$/ => [:white, :bold]},
306
+ numeric: {
307
+ /^[8-f][0-9a-f]$/ => :faint,
308
+ /f/ => :cyan,
309
+ '00' => [:black, :on_red]
310
+ },
311
+ chars: {/[^\.]+/ => :green}
312
+ })
313
+ ```
314
+
315
+ ### Block Configuration
316
+
317
+ ```ruby
318
+ Hexdump.hexdump("hello\0") do |hex|
319
+ hex.type = :uint16_le
320
+ hex.group_chars = :type
321
+ # ...
322
+ end
323
+ # 00000000 6568 6c6c 006f |he|ll|o.|
324
+ # 00000006
325
+ ```
87
326
 
88
327
  ## Benchmarks
89
328
 
90
- Benchmarks show {Hexdump.dump} processing 25M of data.
91
-
92
- ### Ruby 2.7.3
93
-
94
- ```
95
- user system total real
96
- Hexdump.dump (output) 10.283433 0.000748 10.284181 ( 10.328899)
97
- Hexdump.dump width=256 (output) 8.803228 0.005973 8.809201 ( 8.838375)
98
- Hexdump.dump ascii=true (output) 10.740975 0.001903 10.742878 ( 10.779777)
99
- Hexdump.dump word_size=2 (output) 15.163195 0.000989 15.164184 ( 15.220481)
100
- Hexdump.dump word_size=4 (output) 14.279406 0.003840 14.283246 ( 14.345357)
101
- Hexdump.dump word_size=8 (output) 7.715803 0.002879 7.718682 ( 7.746389)
102
- Hexdump.dump (block) 5.543268 0.000980 5.544248 ( 5.561494)
103
- Hexdump.dump width=256 (block) 5.438946 0.000000 5.438946 ( 5.455742)
104
- Hexdump.dump ascii=true (block) 6.082787 0.000924 6.083711 ( 6.106234)
105
- Hexdump.dump word_size=2 (block) 11.439610 0.000983 11.440593 ( 11.483788)
106
- Hexdump.dump word_size=4 (block) 11.111633 0.000954 11.112587 ( 11.158416)
107
- Hexdump.dump word_size=8 (block) 5.397569 0.002896 5.400465 ( 5.426971)
108
- ```
109
-
110
- ### Ruby 3.0.1
111
-
112
- ```
113
- user system total real
114
- Hexdump.dump (output) 12.064022 0.001165 12.065187 ( 12.118272)
115
- Hexdump.dump width=256 (output) 10.228743 0.009920 10.238663 ( 10.279783)
116
- Hexdump.dump ascii=true (output) 12.532913 0.000000 12.532913 ( 12.582665)
117
- Hexdump.dump word_size=2 (output) 17.685782 0.000000 17.685782 ( 17.770686)
118
- Hexdump.dump word_size=4 (output) 15.835564 0.000000 15.835564 ( 15.917552)
119
- Hexdump.dump word_size=8 (output) 8.436831 0.000000 8.436831 ( 8.473445)
120
- Hexdump.dump (block) 6.482589 0.000000 6.482589 ( 6.504816)
121
- Hexdump.dump width=256 (block) 6.360828 0.000000 6.360828 ( 6.383705)
122
- Hexdump.dump ascii=true (block) 6.911868 0.000000 6.911868 ( 6.936795)
123
- Hexdump.dump word_size=2 (block) 13.120488 0.000000 13.120488 ( 13.179957)
124
- Hexdump.dump word_size=4 (block) 12.349516 0.000000 12.349516 ( 12.412972)
125
- Hexdump.dump word_size=8 (block) 5.814830 0.000000 5.814830 ( 5.837822)
126
- ```
127
-
128
- ### JRuby 9.2.16.0
129
-
130
- ```
131
- user system total real
132
- Hexdump.dump (output) 13.090000 0.240000 13.330000 ( 11.226466)
133
- Hexdump.dump width=256 (output) 9.350000 0.030000 9.380000 ( 9.165070)
134
- Hexdump.dump ascii=true (output) 10.910000 0.050000 10.960000 ( 10.665791)
135
- Hexdump.dump word_size=2 (output) 13.760000 0.150000 13.910000 ( 12.268307)
136
- Hexdump.dump word_size=4 (output) 11.940000 0.090000 12.030000 ( 11.107564)
137
- Hexdump.dump word_size=8 (output) 8.170000 0.040000 8.210000 ( 7.419708)
138
- Hexdump.dump (block) 7.840000 0.020000 7.860000 ( 7.777749)
139
- Hexdump.dump width=256 (block) 7.540000 0.000000 7.540000 ( 7.466315)
140
- Hexdump.dump ascii=true (block) 7.680000 0.010000 7.690000 ( 7.622393)
141
- Hexdump.dump word_size=2 (block) 9.830000 0.020000 9.850000 ( 9.693596)
142
- Hexdump.dump word_size=4 (block) 9.010000 0.020000 9.030000 ( 8.998687)
143
- Hexdump.dump word_size=8 (block) 5.740000 0.030000 5.770000 ( 5.709127)
144
- ```
145
-
146
- ### TruffleRuby 21.0.0
147
-
148
- ```
149
- user system total real
150
- Hexdump.dump (output) 25.818995 0.855689 26.674684 ( 22.376015)
151
- Hexdump.dump width=256 (output) 20.489077 0.125966 20.615043 ( 18.301748)
152
- Hexdump.dump ascii=true (output) 25.214678 0.098018 25.312696 ( 21.714985)
153
- Hexdump.dump word_size=2 (output) 28.380387 0.192277 28.572664 ( 23.736887)
154
- Hexdump.dump word_size=4 (output) 31.348977 0.134854 31.483831 ( 27.710968)
155
- Hexdump.dump word_size=8 (output) 18.850093 0.100256 18.950349 ( 13.921720)
156
- Hexdump.dump (block) 7.792878 0.050542 7.843420 ( 6.003789)
157
- Hexdump.dump width=256 (block) 6.526531 0.015898 6.542429 ( 5.777169)
158
- Hexdump.dump ascii=true (block) 7.425399 0.030799 7.456198 ( 5.705369)
159
- Hexdump.dump word_size=2 (block) 12.629775 0.028653 12.658428 ( 11.115049)
160
- Hexdump.dump word_size=4 (block) 20.372094 0.010807 20.382901 ( 19.758073)
161
- Hexdump.dump word_size=8 (block) 8.828653 0.010889 8.839542 ( 8.017241)
329
+ Benchmarks show hexdumping 1Mb of random data.
330
+
331
+ ### Ruby 2.7.4
332
+
333
+ ```
334
+ user system total real
335
+ Hexdump.hexdump(data) 1.148697 0.025829 1.174526 ( 1.183447)
336
+ Hexdump.hexdump(data, repeating: false) 1.050473 0.000000 1.050473 ( 1.057167)
337
+ Hexdump.hexdump(data, chars_column: false) 0.878459 0.002912 0.881371 ( 0.888779)
338
+ Hexdump.hexdump(data, columns: 256) 0.793922 0.008785 0.802707 ( 0.810535)
339
+ Hexdump.hexdump(data, group_columns: 4) 1.309818 0.000000 1.309818 ( 1.320721)
340
+ Hexdump.hexdump(data, group_chars: 4) 1.949181 0.000000 1.949181 ( 1.975533)
341
+ Hexdump.hexdump(data, encoding: :utf8) 1.292495 0.000000 1.292495 ( 1.302071)
342
+ Hexdump.hexdump(data, type: :char) 1.168044 0.000000 1.168044 ( 1.177700)
343
+ Hexdump.hexdump(data, type: :uchar) 1.033165 0.000000 1.033165 ( 1.041185)
344
+ Hexdump.hexdump(data, type: :int8) 1.310548 0.000000 1.310548 ( 1.319847)
345
+ Hexdump.hexdump(data, type: :uint8) 1.035534 0.000000 1.035534 ( 1.041428)
346
+ Hexdump.hexdump(data, type: :int16) 1.351306 0.009906 1.361212 ( 1.370048)
347
+ Hexdump.hexdump(data, type: :int16_le) 1.320781 0.002981 1.323762 ( 1.331747)
348
+ Hexdump.hexdump(data, type: :int16_be) 1.401554 0.003986 1.405540 ( 1.414568)
349
+ Hexdump.hexdump(data, type: :int16_ne) 1.367864 0.000000 1.367864 ( 1.376459)
350
+ Hexdump.hexdump(data, type: :uint16) 1.425247 0.003965 1.429212 ( 1.438618)
351
+ Hexdump.hexdump(data, type: :uint16_le) 1.399240 0.002979 1.402219 ( 1.411098)
352
+ Hexdump.hexdump(data, type: :uint16_be) 1.409289 0.006960 1.416249 ( 1.424767)
353
+ Hexdump.hexdump(data, type: :uint16_ne) 1.288829 0.000001 1.288830 ( 1.296091)
354
+ Hexdump.hexdump(data, type: :int32) 1.089239 0.000000 1.089239 ( 1.094715)
355
+ Hexdump.hexdump(data, type: :int32_le) 1.429353 0.000003 1.429356 ( 1.441620)
356
+ Hexdump.hexdump(data, type: :int32_be) 1.472933 0.000000 1.472933 ( 1.486328)
357
+ Hexdump.hexdump(data, type: :int32_ne) 1.357824 0.000000 1.357824 ( 1.369258)
358
+ Hexdump.hexdump(data, type: :uint32) 1.214704 0.000000 1.214704 ( 1.222920)
359
+ Hexdump.hexdump(data, type: :uint32_le) 1.253424 0.000000 1.253424 ( 1.262441)
360
+ Hexdump.hexdump(data, type: :uint32_be) 1.325268 0.000000 1.325268 ( 1.335447)
361
+ Hexdump.hexdump(data, type: :uint32_ne) 1.314893 0.000819 1.315712 ( 1.328889)
362
+ Hexdump.hexdump(data, type: :int64) 1.083071 0.000000 1.083071 ( 1.092108)
363
+ Hexdump.hexdump(data, type: :int64_le) 1.076378 0.000000 1.076378 ( 1.084785)
364
+ Hexdump.hexdump(data, type: :int64_be) 0.998069 0.000000 0.998069 ( 1.005166)
365
+ Hexdump.hexdump(data, type: :int64_ne) 0.990422 0.000000 0.990422 ( 1.005638)
366
+ Hexdump.hexdump(data, type: :uint64) 1.010946 0.000000 1.010946 ( 1.018339)
367
+ Hexdump.hexdump(data, type: :uint64_le) 0.961576 0.000000 0.961576 ( 0.967806)
368
+ Hexdump.hexdump(data, type: :uint64_be) 0.979367 0.000000 0.979367 ( 0.985515)
369
+ Hexdump.hexdump(data, type: :uint64_ne) 1.017737 0.000000 1.017737 ( 1.024689)
370
+ Hexdump.hexdump(data, type: :float32) 1.237278 0.000000 1.237278 ( 1.245206)
371
+ Hexdump.hexdump(data, type: :float32_le) 1.233321 0.000000 1.233321 ( 1.241154)
372
+ Hexdump.hexdump(data, type: :float32_be) 1.245740 0.000000 1.245740 ( 1.253952)
373
+ Hexdump.hexdump(data, type: :float32_ne) 1.256216 0.000000 1.256216 ( 1.264893)
374
+ Hexdump.hexdump(data, type: :float64) 1.122882 0.000000 1.122882 ( 1.130954)
375
+ Hexdump.hexdump(data, type: :float64_le) 1.117593 0.000000 1.117593 ( 1.125222)
376
+ Hexdump.hexdump(data, type: :float64_be) 1.139602 0.000000 1.139602 ( 1.147980)
377
+ Hexdump.hexdump(data, type: :float64_ne) 1.142568 0.000000 1.142568 ( 1.150949)
378
+ ```
379
+
380
+ ### Ruby 3.0.2
381
+
382
+ ```
383
+ user system total real
384
+ Hexdump.hexdump(data) 0.902383 0.046875 0.949258 ( 0.953623)
385
+ Hexdump.hexdump(data, repeating: false) 0.892407 0.000046 0.892453 ( 0.896401)
386
+ Hexdump.hexdump(data, chars_column: false) 0.705909 0.001029 0.706938 ( 0.709924)
387
+ Hexdump.hexdump(data, columns: 256) 0.627444 0.009986 0.637430 ( 0.640324)
388
+ Hexdump.hexdump(data, group_columns: 4) 1.081550 0.001041 1.082591 ( 1.087987)
389
+ Hexdump.hexdump(data, group_chars: 4) 1.444519 0.000000 1.444519 ( 1.452809)
390
+ Hexdump.hexdump(data, encoding: :utf8) 1.078177 0.000003 1.078180 ( 1.082981)
391
+ Hexdump.hexdump(data, type: :char) 0.865217 0.000000 0.865217 ( 0.868752)
392
+ Hexdump.hexdump(data, type: :uchar) 0.736559 0.000000 0.736559 ( 0.739721)
393
+ Hexdump.hexdump(data, type: :int8) 1.042024 0.000000 1.042024 ( 1.046687)
394
+ Hexdump.hexdump(data, type: :uint8) 0.917350 0.000005 0.917355 ( 0.921428)
395
+ Hexdump.hexdump(data, type: :int16) 1.351638 0.004978 1.356616 ( 1.363879)
396
+ Hexdump.hexdump(data, type: :int16_le) 1.315200 0.006944 1.322144 ( 1.329052)
397
+ Hexdump.hexdump(data, type: :int16_be) 1.421759 0.005966 1.427725 ( 1.435760)
398
+ Hexdump.hexdump(data, type: :int16_ne) 1.444364 0.001995 1.446359 ( 1.454039)
399
+ Hexdump.hexdump(data, type: :uint16) 1.491169 0.001000 1.492169 ( 1.500542)
400
+ Hexdump.hexdump(data, type: :uint16_le) 1.439111 0.000000 1.439111 ( 1.447745)
401
+ Hexdump.hexdump(data, type: :uint16_be) 1.464961 0.000836 1.465797 ( 1.473807)
402
+ Hexdump.hexdump(data, type: :uint16_ne) 1.407008 0.000808 1.407816 ( 1.415236)
403
+ Hexdump.hexdump(data, type: :int32) 1.048519 0.000004 1.048523 ( 1.053326)
404
+ Hexdump.hexdump(data, type: :int32_le) 1.080497 0.000000 1.080497 ( 1.085598)
405
+ Hexdump.hexdump(data, type: :int32_be) 1.033985 0.000000 1.033985 ( 1.038472)
406
+ Hexdump.hexdump(data, type: :int32_ne) 1.057491 0.000000 1.057491 ( 1.062123)
407
+ Hexdump.hexdump(data, type: :uint32) 1.019488 0.000000 1.019488 ( 1.023838)
408
+ Hexdump.hexdump(data, type: :uint32_le) 1.014077 0.000003 1.014080 ( 1.018370)
409
+ Hexdump.hexdump(data, type: :uint32_be) 1.038020 0.000000 1.038020 ( 1.042756)
410
+ Hexdump.hexdump(data, type: :uint32_ne) 1.047465 0.000000 1.047465 ( 1.052377)
411
+ Hexdump.hexdump(data, type: :int64) 0.842281 0.000000 0.842281 ( 0.845988)
412
+ Hexdump.hexdump(data, type: :int64_le) 0.840408 0.000000 0.840408 ( 0.844103)
413
+ Hexdump.hexdump(data, type: :int64_be) 0.845470 0.000002 0.845472 ( 0.849219)
414
+ Hexdump.hexdump(data, type: :int64_ne) 0.843975 0.000000 0.843975 ( 0.847644)
415
+ Hexdump.hexdump(data, type: :uint64) 0.836761 0.000000 0.836761 ( 0.840326)
416
+ Hexdump.hexdump(data, type: :uint64_le) 0.828863 0.000000 0.828863 ( 0.832319)
417
+ Hexdump.hexdump(data, type: :uint64_be) 0.839492 0.000001 0.839493 ( 0.843017)
418
+ Hexdump.hexdump(data, type: :uint64_ne) 0.843799 0.000000 0.843799 ( 0.847764)
419
+ Hexdump.hexdump(data, type: :float32) 1.091306 0.000000 1.091306 ( 1.096429)
420
+ Hexdump.hexdump(data, type: :float32_le) 1.077634 0.000000 1.077634 ( 1.082633)
421
+ Hexdump.hexdump(data, type: :float32_be) 1.085840 0.000986 1.086826 ( 1.092056)
422
+ Hexdump.hexdump(data, type: :float32_ne) 1.093757 0.000000 1.093757 ( 1.099011)
423
+ Hexdump.hexdump(data, type: :float64) 0.873676 0.010942 0.884618 ( 0.888978)
424
+ Hexdump.hexdump(data, type: :float64_le) 0.865006 0.003984 0.868990 ( 0.873156)
425
+ Hexdump.hexdump(data, type: :float64_be) 0.879795 0.009947 0.889742 ( 0.894389)
426
+ Hexdump.hexdump(data, type: :float64_ne) 0.876483 0.010934 0.887417 ( 0.892222)
427
+ ```
428
+
429
+ ### JRuby 9.2.19.0
430
+
431
+ ```
432
+ user system total real
433
+ Hexdump.hexdump(data) 6.440000 0.260000 6.700000 ( 1.990004)
434
+ Hexdump.hexdump(data, repeating: false) 1.920000 0.010000 1.930000 ( 0.973891)
435
+ Hexdump.hexdump(data, chars_column: false) 1.680000 0.010000 1.690000 ( 0.848573)
436
+ Hexdump.hexdump(data, columns: 256) 0.920000 0.010000 0.930000 ( 0.703203)
437
+ Hexdump.hexdump(data, group_columns: 4) 2.070000 0.010000 2.080000 ( 1.119408)
438
+ Hexdump.hexdump(data, group_chars: 4) 2.200000 0.010000 2.210000 ( 1.427454)
439
+ Hexdump.hexdump(data, encoding: :utf8) 2.280000 0.010000 2.290000 ( 1.148070)
440
+ Hexdump.hexdump(data, type: :char) 1.970000 0.020000 1.990000 ( 1.022860)
441
+ Hexdump.hexdump(data, type: :uchar) 0.940000 0.000000 0.940000 ( 0.780674)
442
+ Hexdump.hexdump(data, type: :int8) 1.580000 0.000000 1.580000 ( 1.086830)
443
+ Hexdump.hexdump(data, type: :uint8) 0.980000 0.010000 0.990000 ( 0.937851)
444
+ Hexdump.hexdump(data, type: :int16) 2.730000 0.030000 2.760000 ( 1.571684)
445
+ Hexdump.hexdump(data, type: :int16_le) 1.620000 0.000000 1.620000 ( 1.354835)
446
+ Hexdump.hexdump(data, type: :int16_be) 1.700000 0.010000 1.710000 ( 1.430056)
447
+ Hexdump.hexdump(data, type: :int16_ne) 1.640000 0.000000 1.640000 ( 1.437230)
448
+ Hexdump.hexdump(data, type: :uint16) 2.190000 0.100000 2.290000 ( 1.801601)
449
+ Hexdump.hexdump(data, type: :uint16_le) 1.770000 0.010000 1.780000 ( 1.585609)
450
+ Hexdump.hexdump(data, type: :uint16_be) 1.720000 0.000000 1.720000 ( 1.555715)
451
+ Hexdump.hexdump(data, type: :uint16_ne) 1.760000 0.010000 1.770000 ( 1.540340)
452
+ Hexdump.hexdump(data, type: :int32) 1.430000 0.000000 1.430000 ( 1.133868)
453
+ Hexdump.hexdump(data, type: :int32_le) 1.060000 0.000000 1.060000 ( 1.031721)
454
+ Hexdump.hexdump(data, type: :int32_be) 1.130000 0.010000 1.140000 ( 1.096841)
455
+ Hexdump.hexdump(data, type: :int32_ne) 1.080000 0.000000 1.080000 ( 1.074743)
456
+ Hexdump.hexdump(data, type: :uint32) 1.560000 0.010000 1.570000 ( 1.053369)
457
+ Hexdump.hexdump(data, type: :uint32_le) 1.070000 0.000000 1.070000 ( 1.001372)
458
+ Hexdump.hexdump(data, type: :uint32_be) 1.460000 0.020000 1.480000 ( 1.080869)
459
+ Hexdump.hexdump(data, type: :uint32_ne) 1.120000 0.010000 1.130000 ( 0.876941)
460
+ Hexdump.hexdump(data, type: :int64) 1.510000 0.010000 1.520000 ( 0.865030)
461
+ Hexdump.hexdump(data, type: :int64_le) 0.860000 0.000000 0.860000 ( 0.770903)
462
+ Hexdump.hexdump(data, type: :int64_be) 0.820000 0.000000 0.820000 ( 0.768356)
463
+ Hexdump.hexdump(data, type: :int64_ne) 0.760000 0.010000 0.770000 ( 0.752532)
464
+ Hexdump.hexdump(data, type: :uint64) 2.430000 0.000000 2.430000 ( 1.011133)
465
+ Hexdump.hexdump(data, type: :uint64_le) 0.850000 0.010000 0.860000 ( 0.823235)
466
+ Hexdump.hexdump(data, type: :uint64_be) 0.870000 0.000000 0.870000 ( 0.822799)
467
+ Hexdump.hexdump(data, type: :uint64_ne) 0.900000 0.000000 0.900000 ( 0.829247)
468
+ Hexdump.hexdump(data, type: :float32) 3.700000 0.020000 3.720000 ( 1.862630)
469
+ Hexdump.hexdump(data, type: :float32_le) 1.430000 0.010000 1.440000 ( 1.372024)
470
+ Hexdump.hexdump(data, type: :float32_be) 1.360000 0.010000 1.370000 ( 1.333000)
471
+ Hexdump.hexdump(data, type: :float32_ne) 1.390000 0.000000 1.390000 ( 1.354031)
472
+ Hexdump.hexdump(data, type: :float64) 2.830000 0.030000 2.860000 ( 1.705892)
473
+ Hexdump.hexdump(data, type: :float64_le) 1.370000 0.000000 1.370000 ( 1.356680)
474
+ Hexdump.hexdump(data, type: :float64_be) 1.430000 0.010000 1.440000 ( 1.392404)
475
+ Hexdump.hexdump(data, type: :float64_ne) 1.380000 0.000000 1.380000 ( 1.363983)
476
+ ```
477
+
478
+ ### TruffleRuby 21.2.0.1
479
+
480
+ ```
481
+ user system total real
482
+ Hexdump.hexdump(data) 7.456088 0.230339 7.686427 ( 2.378998)
483
+ Hexdump.hexdump(data, repeating: false) 5.737137 0.150997 5.888134 ( 1.781732)
484
+ Hexdump.hexdump(data, chars_column: false) 6.671704 0.064265 6.735969 ( 2.054377)
485
+ Hexdump.hexdump(data, columns: 256) 4.711081 0.023574 4.734655 ( 1.352932)
486
+ Hexdump.hexdump(data, group_columns: 4) 8.762291 0.133901 8.896192 ( 2.711132)
487
+ Hexdump.hexdump(data, group_chars: 4) 13.382068 0.127633 13.509701 ( 4.128705)
488
+ Hexdump.hexdump(data, encoding: :utf8) 8.591975 0.138969 8.730944 ( 2.676283)
489
+ Hexdump.hexdump(data, type: :char) 6.455997 0.059446 6.515443 ( 1.953656)
490
+ Hexdump.hexdump(data, type: :uchar) 6.201412 0.048587 6.249999 ( 1.732655)
491
+ Hexdump.hexdump(data, type: :int8) 8.712725 0.095197 8.807922 ( 2.587043)
492
+ Hexdump.hexdump(data, type: :uint8) 5.553536 0.074358 5.627894 ( 1.786634)
493
+ Hexdump.hexdump(data, type: :int16) 11.300609 0.114115 11.414724 ( 3.440795)
494
+ Hexdump.hexdump(data, type: :int16_le) 8.040891 0.060503 8.101394 ( 2.388759)
495
+ Hexdump.hexdump(data, type: :int16_be) 6.602434 0.087225 6.689659 ( 2.082091)
496
+ Hexdump.hexdump(data, type: :int16_ne) 5.448411 0.076425 5.524836 ( 1.696039)
497
+ Hexdump.hexdump(data, type: :uint16) 10.081909 0.157579 10.239488 ( 3.106461)
498
+ Hexdump.hexdump(data, type: :uint16_le) 6.847504 0.040543 6.888047 ( 2.069546)
499
+ Hexdump.hexdump(data, type: :uint16_be) 6.730759 0.149299 6.880058 ( 2.147346)
500
+ Hexdump.hexdump(data, type: :uint16_ne) 5.539179 0.108832 5.648011 ( 1.747539)
501
+ Hexdump.hexdump(data, type: :int32) 7.998790 0.058401 8.057191 ( 2.383304)
502
+ Hexdump.hexdump(data, type: :int32_le) 4.650657 0.081202 4.731859 ( 1.412741)
503
+ Hexdump.hexdump(data, type: :int32_be) 11.538588 0.089259 11.627847 ( 3.557763)
504
+ Hexdump.hexdump(data, type: :int32_ne) 9.605673 0.146677 9.752350 ( 2.995870)
505
+ Hexdump.hexdump(data, type: :uint32) 10.404964 0.106136 10.511100 ( 3.118580)
506
+ Hexdump.hexdump(data, type: :uint32_le) 4.851154 0.080325 4.931479 ( 1.463532)
507
+ Hexdump.hexdump(data, type: :uint32_be) 11.293044 0.100121 11.393165 ( 3.539708)
508
+ Hexdump.hexdump(data, type: :uint32_ne) 9.907893 0.122000 10.029893 ( 3.165294)
509
+ Hexdump.hexdump(data, type: :int64) 9.103719 0.102995 9.206714 ( 2.775106)
510
+ Hexdump.hexdump(data, type: :int64_le) 9.304751 0.180642 9.485393 ( 2.922495)
511
+ Hexdump.hexdump(data, type: :int64_be) 7.166353 0.089344 7.255697 ( 2.215438)
512
+ Hexdump.hexdump(data, type: :int64_ne) 6.874170 0.090186 6.964356 ( 2.113975)
513
+ Hexdump.hexdump(data, type: :uint64) 12.997911 0.165758 13.163669 ( 4.081488)
514
+ Hexdump.hexdump(data, type: :uint64_le) 8.949650 0.130855 9.080505 ( 2.712645)
515
+ Hexdump.hexdump(data, type: :uint64_be) 8.948030 0.173500 9.121530 ( 2.842953)
516
+ Hexdump.hexdump(data, type: :uint64_ne) 8.055399 0.153749 8.209148 ( 2.547932)
517
+ Hexdump.hexdump(data, type: :float32) 14.345624 0.241224 14.586848 ( 4.508393)
518
+ Hexdump.hexdump(data, type: :float32_le) 10.454524 0.103136 10.557660 ( 3.112175)
519
+ Hexdump.hexdump(data, type: :float32_be) 11.073294 0.202252 11.275546 ( 3.443881)
520
+ Hexdump.hexdump(data, type: :float32_ne) 9.990956 0.091216 10.082172 ( 3.022276)
521
+ Hexdump.hexdump(data, type: :float64) 16.629231 0.279989 16.909220 ( 5.163906)
522
+ Hexdump.hexdump(data, type: :float64_le) 13.761375 0.190385 13.951760 ( 4.129403)
523
+ Hexdump.hexdump(data, type: :float64_be) 16.121047 0.277863 16.398910 ( 5.019326)
524
+ Hexdump.hexdump(data, type: :float64_ne) 8.873162 0.068414 8.941576 ( 4.748072)
162
525
  ```
163
526
 
164
527
  ## Copyright