hikari_buffer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/Rakefile +44 -0
- data/bench/growth_stress.rb +17 -0
- data/bench/marshal.rb +33 -0
- data/bench/mixed_workload.rb +31 -0
- data/bench/protocol.rb +21 -0
- data/bench/read_bytes.rb +16 -0
- data/bench/read_string.rb +16 -0
- data/bench/sequential_packet.rb +31 -0
- data/bench/stringio.rb +23 -0
- data/bench/write_bytes.rb +21 -0
- data/bench/write_string.rb +21 -0
- data/bench/write_u32.rb +14 -0
- data/ext/hikari_buffer/buffer.c +517 -0
- data/ext/hikari_buffer/buffer.h +15 -0
- data/ext/hikari_buffer/convert.c +141 -0
- data/ext/hikari_buffer/convert.h +38 -0
- data/ext/hikari_buffer/extconf.rb +10 -0
- data/ext/hikari_buffer/hikari_buffer.c +12 -0
- data/ext/hikari_buffer/hikari_buffer.h +9 -0
- data/ext/hikari_buffer/io.c +64 -0
- data/ext/hikari_buffer/io.h +12 -0
- data/lib/hikari_buffer/version.rb +5 -0
- data/lib/hikari_buffer.rb +9 -0
- data/sig/hikari_buffer.rbs +4 -0
- metadata +74 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 540d2520c67449dd639af257f9a415942f42f4e50a885e15922a9ea61bc22fc5
|
|
4
|
+
data.tar.gz: 80cd2f004b6434f2c9927e3af94e2563d766c2dbfe27ed7d46c169bcd7f68370
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8c4e41cb1fdd5fec74fc896d864b48fdfcfa3a4e925570ef6187125dca187ba4b3bd579087201b45d336b963519e4232cdd72c598345d5364953de037bf995ee
|
|
7
|
+
data.tar.gz: 88a7e464c4f86a40827ab44a23acb66358f9f6f9a8860f75f5b77e4b77b2442edf5291f61ce58f43a0abcf29bc30a2b80fcd6be2473d48c94a36bab70a98e29b
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## [0.1.0] - 2026-08-05
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
|
|
5
|
+
- Native C extension
|
|
6
|
+
- Integer serialization (signed/unsigned)
|
|
7
|
+
- Floating point serialization
|
|
8
|
+
- Boolean serialization
|
|
9
|
+
- String serialization
|
|
10
|
+
- Byte serialization
|
|
11
|
+
- Peek operations
|
|
12
|
+
- Skip operation
|
|
13
|
+
- Automatic buffer growth
|
|
14
|
+
- Comprehensive test suite
|
|
15
|
+
- Benchmarks
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"Hikari Buffer" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact the maintainer through GitHub by opening a private discussion or issue.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TODO: Write your name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Hikari Buffer
|
|
2
|
+
|
|
3
|
+
[](https://github.com/AntarMukhopadhyaya/hikari-buffer/actions/workflows/main.yml)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A fast, lightweight binary buffer for Ruby built as a native C extension. Hikari Buffer provides efficient serialization and deserialization of primitive data types, strings, and raw bytes through a clean, chainable API.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
* ๐ Native C extension for maximum performance
|
|
11
|
+
* ๐ฆ Binary serialization and deserialization
|
|
12
|
+
* ๐ข Signed integers (`i8`, `i16`, `i32`, `i64`)
|
|
13
|
+
* ๐ข Unsigned integers (`u8`, `u16`, `u32`, `u64`)
|
|
14
|
+
* ๐ Floating-point numbers (`f32`, `f64`)
|
|
15
|
+
* โ
Boolean support
|
|
16
|
+
* ๐ UTF-8 string serialization
|
|
17
|
+
* ๐ Raw byte serialization
|
|
18
|
+
* ๐ฏ Cursor-based reading and writing
|
|
19
|
+
* ๐ Automatic buffer growth
|
|
20
|
+
* ๐งช Comprehensive RSpec test suite
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
### RubyGems
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
gem install hikari_buffer
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Bundler
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
gem "hikari_buffer"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
require "hikari_buffer"
|
|
40
|
+
|
|
41
|
+
buffer = Hikari::Buffer.new
|
|
42
|
+
|
|
43
|
+
buffer
|
|
44
|
+
.write_u32(42)
|
|
45
|
+
.write_bool(true)
|
|
46
|
+
.write_f64(Math::PI)
|
|
47
|
+
.write_string("Hello, Hikari!")
|
|
48
|
+
|
|
49
|
+
buffer.rewind
|
|
50
|
+
|
|
51
|
+
puts buffer.read_u32
|
|
52
|
+
puts buffer.read_bool
|
|
53
|
+
puts buffer.read_f64
|
|
54
|
+
puts buffer.read_string
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Supported Types
|
|
58
|
+
|
|
59
|
+
| Type | Read | Write |
|
|
60
|
+
| ------ | :--: | :---: |
|
|
61
|
+
| u8 | โ
| โ
|
|
|
62
|
+
| u16 | โ
| โ
|
|
|
63
|
+
| u32 | โ
| โ
|
|
|
64
|
+
| u64 | โ
| โ
|
|
|
65
|
+
| i8 | โ
| โ
|
|
|
66
|
+
| i16 | โ
| โ
|
|
|
67
|
+
| i32 | โ
| โ
|
|
|
68
|
+
| i64 | โ
| โ
|
|
|
69
|
+
| f32 | โ
| โ
|
|
|
70
|
+
| f64 | โ
| โ
|
|
|
71
|
+
| bool | โ
| โ
|
|
|
72
|
+
| bytes | โ
| โ
|
|
|
73
|
+
| string | โ
| โ
|
|
|
74
|
+
|
|
75
|
+
## Buffer API
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
buffer.capacity
|
|
79
|
+
buffer.size
|
|
80
|
+
buffer.cursor
|
|
81
|
+
buffer.tell
|
|
82
|
+
buffer.remaining
|
|
83
|
+
|
|
84
|
+
buffer.seek(position)
|
|
85
|
+
buffer.rewind
|
|
86
|
+
buffer.clear
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
Clone the repository and install dependencies:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
git clone https://github.com/AntarMukhopadhyaya/hikari-buffer.git
|
|
95
|
+
cd hikari-buffer
|
|
96
|
+
bundle install
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Compile the native extension:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
bundle exec rake compile
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Run the test suite:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
bundle exec rspec
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Run RuboCop:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
bundle exec rubocop
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Roadmap
|
|
118
|
+
|
|
119
|
+
* [x] Primitive integer serialization
|
|
120
|
+
* [x] Floating-point serialization
|
|
121
|
+
* [x] Boolean serialization
|
|
122
|
+
* [x] String serialization
|
|
123
|
+
* [x] Raw byte serialization
|
|
124
|
+
* [x] Automatic buffer growth
|
|
125
|
+
* [ ] Peek operations
|
|
126
|
+
* [ ] Endianness support
|
|
127
|
+
* [ ] Array serialization
|
|
128
|
+
* [ ] UUID serialization
|
|
129
|
+
* [ ] Benchmarks
|
|
130
|
+
* [ ] Precompiled native gems for Windows, Linux, and macOS
|
|
131
|
+
|
|
132
|
+
## Contributing
|
|
133
|
+
|
|
134
|
+
Bug reports, feature requests, and pull requests are welcome.
|
|
135
|
+
|
|
136
|
+
If you'd like to contribute:
|
|
137
|
+
|
|
138
|
+
1. Fork the repository
|
|
139
|
+
2. Create a feature branch
|
|
140
|
+
3. Add tests for your changes
|
|
141
|
+
4. Ensure all tests pass
|
|
142
|
+
5. Open a Pull Request
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
Released under the MIT License. See the `LICENSE` file for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rspec/core/rake_task"
|
|
5
|
+
|
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
7
|
+
|
|
8
|
+
require "rubocop/rake_task"
|
|
9
|
+
|
|
10
|
+
RuboCop::RakeTask.new
|
|
11
|
+
namespace :bench do
|
|
12
|
+
Dir.glob("bench/*.rb").sort.each do |file|
|
|
13
|
+
name = File.basename(file, ".rb")
|
|
14
|
+
|
|
15
|
+
desc "Run #{name} benchmark"
|
|
16
|
+
task name.to_sym do
|
|
17
|
+
ruby file
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
desc "Run all benchmarks"
|
|
22
|
+
task :all do
|
|
23
|
+
Dir.glob("bench/*.rb").sort.each do |file|
|
|
24
|
+
puts
|
|
25
|
+
puts "=" * 80
|
|
26
|
+
puts "Running #{File.basename(file)}"
|
|
27
|
+
puts "=" * 80
|
|
28
|
+
|
|
29
|
+
ruby file
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
require "rake/extensiontask"
|
|
35
|
+
|
|
36
|
+
task build: :compile
|
|
37
|
+
|
|
38
|
+
GEMSPEC = Gem::Specification.load("hikari_buffer.gemspec")
|
|
39
|
+
|
|
40
|
+
Rake::ExtensionTask.new("hikari_buffer", GEMSPEC) do |ext|
|
|
41
|
+
ext.lib_dir = "lib/hikari_buffer"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
task default: %i[clobber compile spec rubocop]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
|
|
5
|
+
require "hikari_buffer"
|
|
6
|
+
|
|
7
|
+
Benchmark.ips do |x|
|
|
8
|
+
x.report("Growth (8 -> many)") do
|
|
9
|
+
buf = Hikari::Buffer.new(8)
|
|
10
|
+
|
|
11
|
+
10_000.times do |i|
|
|
12
|
+
buf.write_u32(i)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
x.compare!
|
|
17
|
+
end
|
data/bench/marshal.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "hikari_buffer"
|
|
5
|
+
|
|
6
|
+
buf = Hikari::Buffer.new
|
|
7
|
+
|
|
8
|
+
Benchmark.ips do |x|
|
|
9
|
+
x.report("Marshal") do
|
|
10
|
+
Marshal.dump({
|
|
11
|
+
hp: 100,
|
|
12
|
+
mana: 50,
|
|
13
|
+
x: 12.3,
|
|
14
|
+
y: 45.6,
|
|
15
|
+
alive: true,
|
|
16
|
+
level: 99
|
|
17
|
+
})
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
x.report("Hikari") do
|
|
21
|
+
buf.clear
|
|
22
|
+
|
|
23
|
+
buf
|
|
24
|
+
.write_i32(100)
|
|
25
|
+
.write_i32(50)
|
|
26
|
+
.write_f32(12.3)
|
|
27
|
+
.write_f32(45.6)
|
|
28
|
+
.write_bool(true)
|
|
29
|
+
.write_u16(99)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
x.compare!
|
|
33
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "hikari_buffer"
|
|
5
|
+
|
|
6
|
+
TEXT = "Hello World"
|
|
7
|
+
|
|
8
|
+
buf = Hikari::Buffer.new
|
|
9
|
+
|
|
10
|
+
Benchmark.ips do |x|
|
|
11
|
+
x.report("Array#pack") do
|
|
12
|
+
[
|
|
13
|
+
42,
|
|
14
|
+
-1234,
|
|
15
|
+
3.1415926535
|
|
16
|
+
].pack("L<q<d") + [1].pack("C") + [TEXT.bytesize].pack("L<") + TEXT
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
x.report("Hikari") do
|
|
20
|
+
buf.clear
|
|
21
|
+
|
|
22
|
+
buf
|
|
23
|
+
.write_u32(42)
|
|
24
|
+
.write_i64(-1234)
|
|
25
|
+
.write_f64(3.1415926535)
|
|
26
|
+
.write_bool(true)
|
|
27
|
+
.write_string(TEXT)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
x.compare!
|
|
31
|
+
end
|
data/bench/protocol.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
|
|
5
|
+
require "hikari_buffer"
|
|
6
|
+
|
|
7
|
+
buf = Hikari::Buffer.new
|
|
8
|
+
|
|
9
|
+
Benchmark.ips do |x|
|
|
10
|
+
x.report("Protocol") do
|
|
11
|
+
buf.clear
|
|
12
|
+
|
|
13
|
+
buf
|
|
14
|
+
.write_u16(0xCAFE)
|
|
15
|
+
.write_u32(100)
|
|
16
|
+
.write_bool(true)
|
|
17
|
+
.write_f64(99.5)
|
|
18
|
+
.write_string("Player")
|
|
19
|
+
.write_bytes("abcd")
|
|
20
|
+
end
|
|
21
|
+
end
|
data/bench/read_bytes.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "hikari_buffer"
|
|
5
|
+
|
|
6
|
+
DATA = Random.bytes(512)
|
|
7
|
+
|
|
8
|
+
buf = Hikari::Buffer.new
|
|
9
|
+
buf.write_bytes(DATA)
|
|
10
|
+
|
|
11
|
+
Benchmark.ips do |x|
|
|
12
|
+
x.report("Hikari") do
|
|
13
|
+
buf.rewind
|
|
14
|
+
buf.read_bytes(DATA.bytesize)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "hikari_buffer"
|
|
5
|
+
|
|
6
|
+
TEXT = "Hello, Hikari Buffer!"
|
|
7
|
+
|
|
8
|
+
buf = Hikari::Buffer.new
|
|
9
|
+
buf.write_string(TEXT)
|
|
10
|
+
|
|
11
|
+
Benchmark.ips do |x|
|
|
12
|
+
x.report("Hikari") do
|
|
13
|
+
buf.rewind
|
|
14
|
+
buf.read_string
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "hikari_buffer"
|
|
5
|
+
|
|
6
|
+
TEXT = "Hello"
|
|
7
|
+
|
|
8
|
+
buf = Hikari::Buffer.new
|
|
9
|
+
|
|
10
|
+
Benchmark.ips do |x|
|
|
11
|
+
x.report("Hikari packet") do
|
|
12
|
+
buf.clear
|
|
13
|
+
|
|
14
|
+
buf
|
|
15
|
+
.write_u8(42)
|
|
16
|
+
.write_i16(-123)
|
|
17
|
+
.write_u32(999_999)
|
|
18
|
+
.write_f64(Math::PI)
|
|
19
|
+
.write_bool(true)
|
|
20
|
+
.write_string(TEXT)
|
|
21
|
+
|
|
22
|
+
buf.rewind
|
|
23
|
+
|
|
24
|
+
buf.read_u8
|
|
25
|
+
buf.read_i16
|
|
26
|
+
buf.read_u32
|
|
27
|
+
buf.read_f64
|
|
28
|
+
buf.read_bool
|
|
29
|
+
buf.read_string
|
|
30
|
+
end
|
|
31
|
+
end
|
data/bench/stringio.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "stringio"
|
|
5
|
+
|
|
6
|
+
require "hikari_buffer"
|
|
7
|
+
|
|
8
|
+
buf = Hikari::Buffer.new
|
|
9
|
+
io = StringIO.new
|
|
10
|
+
|
|
11
|
+
Benchmark.ips do |x|
|
|
12
|
+
x.report("StringIO") do
|
|
13
|
+
io.rewind
|
|
14
|
+
io.write([123].pack("L"))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
x.report("Hikari") do
|
|
18
|
+
buf.clear
|
|
19
|
+
buf.write_u32(123)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
x.compare!
|
|
23
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "hikari_buffer"
|
|
5
|
+
|
|
6
|
+
DATA = Random.bytes(512)
|
|
7
|
+
|
|
8
|
+
buf = Hikari::Buffer.new
|
|
9
|
+
|
|
10
|
+
Benchmark.ips do |x|
|
|
11
|
+
x.report("String#dup") do
|
|
12
|
+
DATA.dup
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
x.report("Hikari") do
|
|
16
|
+
buf.clear
|
|
17
|
+
buf.write_bytes(DATA)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
x.compare!
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "hikari_buffer"
|
|
5
|
+
|
|
6
|
+
TEXT = "Hello, Hikari Buffer!"
|
|
7
|
+
|
|
8
|
+
buf = Hikari::Buffer.new
|
|
9
|
+
|
|
10
|
+
Benchmark.ips do |x|
|
|
11
|
+
x.report("String#dup") do
|
|
12
|
+
TEXT.dup
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
x.report("Hikari") do
|
|
16
|
+
buf.clear
|
|
17
|
+
buf.write_string(TEXT)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
x.compare!
|
|
21
|
+
end
|
data/bench/write_u32.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark/ips"
|
|
4
|
+
require "hikari_buffer"
|
|
5
|
+
buf = Hikari::Buffer.new
|
|
6
|
+
Benchmark.ips do |x|
|
|
7
|
+
x.report("Array#pack") do
|
|
8
|
+
[123_456_789].pack("L")
|
|
9
|
+
end
|
|
10
|
+
x.report("Hikari") do
|
|
11
|
+
buf.write_u32(123_456_789)
|
|
12
|
+
end
|
|
13
|
+
x.compare!
|
|
14
|
+
end
|