bin_utils 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module BinUtils
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/test/benchmark.rb ADDED
@@ -0,0 +1,171 @@
1
+ require 'benchmark'
2
+ require 'bin_utils'
3
+
4
+ N = (ARGV[0] || 1_000_000).to_i
5
+ a = 'asdfzxcvqwerasdfzxcvqwer1234'.force_encoding('binary').freeze
6
+
7
+ EMPTY = ''.freeze
8
+ _V = 'V'.freeze
9
+ _Vv = 'Vv'.freeze
10
+ _Vvw = 'Vvw'.freeze
11
+ _VvwQ = 'VvwQ'.freeze
12
+ _VV = 'VV'.freeze
13
+ _VVv = 'VVv'.freeze
14
+ _vVV = 'vVV'.freeze
15
+ _VVn = 'VVn'.freeze
16
+ _nVw = 'nVw'.freeze
17
+ _w = 'w*'.freeze
18
+
19
+ Benchmark.bmbm(6) do |x|
20
+ x.report('get i32le') { N.times{|_|
21
+ i = ::BinUtils.get_int32_le(a)
22
+ } }
23
+ x.report('get i32le i32le') { N.times{|_|
24
+ i = ::BinUtils.get_int32_le(a); i2 = ::BinUtils.get_int32_le(a, 4)
25
+ } }
26
+ x.report('get i32le i32le i16be') { N.times{|_|
27
+ i = ::BinUtils.get_int32_le(a); i2 = ::BinUtils.get_int32_le(a, 4)
28
+ i3 = ::BinUtils.get_int16_be(a, 9)
29
+ } }
30
+ x.report('get i16be i32le ber') { N.times{|_|
31
+ i = ::BinUtils.get_int16_be(a); i2 = ::BinUtils.get_int32_le(a, 2)
32
+ i3 = ::BinUtils.get_ber(a, 6)
33
+ } }
34
+ x.report('unpack i32le') { N.times{|_| i, = a.unpack(_V)} }
35
+ x.report('unpack i32le`') { N.times{|_| i = a.unpack(_V)[0]} }
36
+ x.report('unpack i32le i32le') { N.times{|_| i, i2 = a.unpack(_VV)} }
37
+ x.report('unpack i32le i32le i16be') { N.times{|_| i, i2, i3 = a.unpack(_VVn)} }
38
+ x.report('unpack i16be i32le ber') { N.times{|_| i, i2, i3 = a.unpack(_nVw)} }
39
+ x.report('slice i32le') { N.times{|_|
40
+ b = a.dup
41
+ i = ::BinUtils.slice_int32_le!(b)
42
+ } }
43
+ x.report('slice i32le i16le') { N.times{|_|
44
+ b = a.dup
45
+ i = ::BinUtils.slice_int32_le!(b)
46
+ i2 = ::BinUtils.slice_int16_le!(b)
47
+ } }
48
+ x.report('slice i32le i16le ber') { N.times{|_|
49
+ b = a.dup
50
+ i = ::BinUtils.slice_int32_le!(b)
51
+ i2 = ::BinUtils.slice_int16_le!(b)
52
+ i3 = ::BinUtils.slice_ber!(b)
53
+ } }
54
+ x.report('slice i32le i16le ber i64le') { N.times{|_|
55
+ b = a.dup
56
+ i = ::BinUtils.slice_int32_le!(b)
57
+ i2 = ::BinUtils.slice_int16_le!(b)
58
+ i3 = ::BinUtils.slice_ber!(b)
59
+ i4 = ::BinUtils.slice_int64_le!(b)
60
+ } }
61
+ x.report('cut unpack i32le') { N.times{|_|
62
+ b = a.dup
63
+ i, = b.unpack(_V)
64
+ b[0, 4] = EMPTY
65
+ } }
66
+ x.report('cut unpack i32le i16le') { N.times{|_|
67
+ b = a.dup
68
+ i, i2 = b.unpack(_Vv)
69
+ b[0, 6] = EMPTY
70
+ } }
71
+ x.report('cut unpack i32le i16le ber') { N.times{|_|
72
+ b = a.dup
73
+ i, i2, i3 = b.unpack(_Vvw)
74
+ if i3 < 128
75
+ b[0, 7] = EMPTY
76
+ else
77
+ b[0, 8] = EMPTY # simplify ber size only to two cases
78
+ end
79
+ } }
80
+ x.report('cut unpack i32le i16le ber i64le') { N.times{|_|
81
+ b = a.dup
82
+ i, i2, i3, i4 = b.unpack(_VvwQ)
83
+ if i3 < 128
84
+ b[0, 15] = EMPTY
85
+ else
86
+ b[0, 16] = EMPTY # simplify ber size only to two cases
87
+ end
88
+ } }
89
+ x.report('create i32le') { N.times{|i|
90
+ b = ::BinUtils.append_int32_le!(nil, i)
91
+ } }
92
+ x.report('create i32le i32le') { N.times{|i|
93
+ b = ::BinUtils.append_int32_le!(nil, i, i+1)
94
+ } }
95
+ x.report('create i32le i32le i16le') { N.times{|i|
96
+ b = ::BinUtils.append_int32_le!(nil, i, i+1)
97
+ ::BinUtils.append_int16_le!(b, i+2)
98
+ } }
99
+ x.report('create i16le i32le i32le') { N.times{|i|
100
+ b = ::BinUtils.append_int16_int32_le!(nil, i, i+1, i+2)
101
+ } }
102
+ x.report('create i16be i32le ber') { N.times{|i|
103
+ b = ::BinUtils.append_int16_be!(nil, i)
104
+ ::BinUtils.append_int32_le!(b, i)
105
+ ::BinUtils.append_ber!(b, i+2)
106
+ } }
107
+ x.report('append i32le') { N.times{|i|
108
+ b = a.dup
109
+ ::BinUtils.append_int32_le!(b, i)
110
+ } }
111
+ x.report('append i32le i32le') { N.times{|i|
112
+ b = a.dup
113
+ ::BinUtils.append_int32_le!(b, i, i+1)
114
+ } }
115
+ x.report('append i32le i32le i16le') { N.times{|i|
116
+ b = a.dup
117
+ ::BinUtils.append_int32_le!(b, i, i+1)
118
+ ::BinUtils.append_int16_le!(b, i+2)
119
+ } }
120
+ x.report('append i16le i32le i32le') { N.times{|i|
121
+ b = a.dup
122
+ ::BinUtils.append_int16_int32_le!(b, i, i+1, i+2)
123
+ } }
124
+ x.report('append i16be i32le ber') { N.times{|i|
125
+ b = a.dup
126
+ ::BinUtils.append_int16_be!(b, i)
127
+ ::BinUtils.append_int32_le!(b, i)
128
+ ::BinUtils.append_ber!(b, i+2)
129
+ } }
130
+ x.report('pack i32le') { N.times{|i|
131
+ b = [i].pack(_V)
132
+ } }
133
+ x.report('pack i32le i32le') { N.times{|i|
134
+ b = [i, i+1].pack(_VV)
135
+ } }
136
+ x.report('pack i32le i32le i16le') { N.times{|i|
137
+ b = [i, i+1, i+2].pack(_VVv)
138
+ } }
139
+ x.report('pack i16le i32le i32le') { N.times{|i|
140
+ b = [i, i+1, i+2].pack(_vVV)
141
+ } }
142
+ x.report('pack i16be i32le ber') { N.times{|i|
143
+ b = [i, i+1, i+2].pack(_nVw)
144
+ } }
145
+ x.report('pack append i32le') { N.times{|i|
146
+ b = a.dup
147
+ b << [i].pack(_V)
148
+ } }
149
+ x.report('pack append i32le i32le') { N.times{|i|
150
+ b = a.dup
151
+ b << [i, i+1].pack(_VV)
152
+ } }
153
+ x.report('pack append i32le i32le i16le') { N.times{|i|
154
+ b = a.dup
155
+ b << [i, i+1, i+2].pack(_VVv)
156
+ } }
157
+ x.report('pack append i16le i32le i32le') { N.times{|i|
158
+ b = a.dup
159
+ b << [i, i+1, i+2].pack(_vVV)
160
+ } }
161
+ x.report('pack append i16be i32le ber') { N.times{|i|
162
+ b = a.dup
163
+ b << [i, i+1, i+2].pack(_nVw)
164
+ } }
165
+ x.report('create ber array') { arr = [1,10,100,1000,10000,100000,1000000]; N.times {|_|
166
+ ::BinUtils.append_ber!(nil, arr)
167
+ } }
168
+ x.report('pack ber array') { arr = [1,10,100,1000,10000,100000,1000000]; N.times {|_|
169
+ arr.pack(_w)
170
+ } }
171
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bin_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: utils for extracting binary integers from binary string and packing them
15
15
  back
@@ -25,6 +25,7 @@ files:
25
25
  - lib/bin_utils.rb
26
26
  - lib/bin_utils/pure_ruby.rb
27
27
  - lib/bin_utils/version.rb
28
+ - test/benchmark.rb
28
29
  - test/test_bin_utils.rb
29
30
  homepage: https://github.com/funny-falcon/bin_utils
30
31
  licenses: []
@@ -53,5 +54,6 @@ specification_version: 3
53
54
  summary: Faster alternative to String#unpack and Array#unpack, though not as complete
54
55
  as those methods
55
56
  test_files:
57
+ - test/benchmark.rb
56
58
  - test/test_bin_utils.rb
57
59
  has_rdoc: