rbcsv 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.
data/Cargo.lock ADDED
@@ -0,0 +1,417 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.3"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "bindgen"
16
+ version = "0.69.5"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
19
+ dependencies = [
20
+ "bitflags",
21
+ "cexpr",
22
+ "clang-sys",
23
+ "itertools",
24
+ "lazy_static",
25
+ "lazycell",
26
+ "proc-macro2",
27
+ "quote",
28
+ "regex",
29
+ "rustc-hash",
30
+ "shlex",
31
+ "syn",
32
+ ]
33
+
34
+ [[package]]
35
+ name = "bitflags"
36
+ version = "2.9.4"
37
+ source = "registry+https://github.com/rust-lang/crates.io-index"
38
+ checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
39
+
40
+ [[package]]
41
+ name = "cexpr"
42
+ version = "0.6.0"
43
+ source = "registry+https://github.com/rust-lang/crates.io-index"
44
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
45
+ dependencies = [
46
+ "nom",
47
+ ]
48
+
49
+ [[package]]
50
+ name = "cfg-if"
51
+ version = "1.0.3"
52
+ source = "registry+https://github.com/rust-lang/crates.io-index"
53
+ checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
54
+
55
+ [[package]]
56
+ name = "clang-sys"
57
+ version = "1.8.1"
58
+ source = "registry+https://github.com/rust-lang/crates.io-index"
59
+ checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
60
+ dependencies = [
61
+ "glob",
62
+ "libc",
63
+ "libloading",
64
+ ]
65
+
66
+ [[package]]
67
+ name = "csv"
68
+ version = "1.3.1"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+ checksum = "acdc4883a9c96732e4733212c01447ebd805833b7275a73ca3ee080fd77afdaf"
71
+ dependencies = [
72
+ "csv-core",
73
+ "itoa",
74
+ "ryu",
75
+ "serde",
76
+ ]
77
+
78
+ [[package]]
79
+ name = "csv-core"
80
+ version = "0.1.12"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+ checksum = "7d02f3b0da4c6504f86e9cd789d8dbafab48c2321be74e9987593de5a894d93d"
83
+ dependencies = [
84
+ "memchr",
85
+ ]
86
+
87
+ [[package]]
88
+ name = "either"
89
+ version = "1.15.0"
90
+ source = "registry+https://github.com/rust-lang/crates.io-index"
91
+ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
92
+
93
+ [[package]]
94
+ name = "glob"
95
+ version = "0.3.3"
96
+ source = "registry+https://github.com/rust-lang/crates.io-index"
97
+ checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
98
+
99
+ [[package]]
100
+ name = "itertools"
101
+ version = "0.12.1"
102
+ source = "registry+https://github.com/rust-lang/crates.io-index"
103
+ checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
104
+ dependencies = [
105
+ "either",
106
+ ]
107
+
108
+ [[package]]
109
+ name = "itoa"
110
+ version = "1.0.15"
111
+ source = "registry+https://github.com/rust-lang/crates.io-index"
112
+ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
113
+
114
+ [[package]]
115
+ name = "lazy_static"
116
+ version = "1.5.0"
117
+ source = "registry+https://github.com/rust-lang/crates.io-index"
118
+ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
119
+
120
+ [[package]]
121
+ name = "lazycell"
122
+ version = "1.3.0"
123
+ source = "registry+https://github.com/rust-lang/crates.io-index"
124
+ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
125
+
126
+ [[package]]
127
+ name = "libc"
128
+ version = "0.2.175"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
131
+
132
+ [[package]]
133
+ name = "libloading"
134
+ version = "0.8.8"
135
+ source = "registry+https://github.com/rust-lang/crates.io-index"
136
+ checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
137
+ dependencies = [
138
+ "cfg-if",
139
+ "windows-targets",
140
+ ]
141
+
142
+ [[package]]
143
+ name = "magnus"
144
+ version = "0.6.4"
145
+ source = "registry+https://github.com/rust-lang/crates.io-index"
146
+ checksum = "b1597ef40aa8c36be098249e82c9a20cf7199278ac1c1a1a995eeead6a184479"
147
+ dependencies = [
148
+ "magnus-macros",
149
+ "rb-sys",
150
+ "rb-sys-env",
151
+ "seq-macro",
152
+ ]
153
+
154
+ [[package]]
155
+ name = "magnus-macros"
156
+ version = "0.6.0"
157
+ source = "registry+https://github.com/rust-lang/crates.io-index"
158
+ checksum = "5968c820e2960565f647819f5928a42d6e874551cab9d88d75e3e0660d7f71e3"
159
+ dependencies = [
160
+ "proc-macro2",
161
+ "quote",
162
+ "syn",
163
+ ]
164
+
165
+ [[package]]
166
+ name = "memchr"
167
+ version = "2.7.5"
168
+ source = "registry+https://github.com/rust-lang/crates.io-index"
169
+ checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
170
+
171
+ [[package]]
172
+ name = "minimal-lexical"
173
+ version = "0.2.1"
174
+ source = "registry+https://github.com/rust-lang/crates.io-index"
175
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
176
+
177
+ [[package]]
178
+ name = "nom"
179
+ version = "7.1.3"
180
+ source = "registry+https://github.com/rust-lang/crates.io-index"
181
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
182
+ dependencies = [
183
+ "memchr",
184
+ "minimal-lexical",
185
+ ]
186
+
187
+ [[package]]
188
+ name = "proc-macro2"
189
+ version = "1.0.101"
190
+ source = "registry+https://github.com/rust-lang/crates.io-index"
191
+ checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
192
+ dependencies = [
193
+ "unicode-ident",
194
+ ]
195
+
196
+ [[package]]
197
+ name = "quote"
198
+ version = "1.0.40"
199
+ source = "registry+https://github.com/rust-lang/crates.io-index"
200
+ checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
201
+ dependencies = [
202
+ "proc-macro2",
203
+ ]
204
+
205
+ [[package]]
206
+ name = "r_csv"
207
+ version = "0.1.0"
208
+ dependencies = [
209
+ "csv",
210
+ "magnus",
211
+ ]
212
+
213
+ [[package]]
214
+ name = "rb-sys"
215
+ version = "0.9.117"
216
+ source = "registry+https://github.com/rust-lang/crates.io-index"
217
+ checksum = "f900d1ce4629a2ebffaf5de74bd8f9c1188d4c5ed406df02f97e22f77a006f44"
218
+ dependencies = [
219
+ "rb-sys-build",
220
+ ]
221
+
222
+ [[package]]
223
+ name = "rb-sys-build"
224
+ version = "0.9.117"
225
+ source = "registry+https://github.com/rust-lang/crates.io-index"
226
+ checksum = "ef1e9c857028f631056bcd6d88cec390c751e343ce2223ddb26d23eb4a151d59"
227
+ dependencies = [
228
+ "bindgen",
229
+ "lazy_static",
230
+ "proc-macro2",
231
+ "quote",
232
+ "regex",
233
+ "shell-words",
234
+ "syn",
235
+ ]
236
+
237
+ [[package]]
238
+ name = "rb-sys-env"
239
+ version = "0.1.2"
240
+ source = "registry+https://github.com/rust-lang/crates.io-index"
241
+ checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
242
+
243
+ [[package]]
244
+ name = "regex"
245
+ version = "1.11.2"
246
+ source = "registry+https://github.com/rust-lang/crates.io-index"
247
+ checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912"
248
+ dependencies = [
249
+ "aho-corasick",
250
+ "memchr",
251
+ "regex-automata",
252
+ "regex-syntax",
253
+ ]
254
+
255
+ [[package]]
256
+ name = "regex-automata"
257
+ version = "0.4.10"
258
+ source = "registry+https://github.com/rust-lang/crates.io-index"
259
+ checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6"
260
+ dependencies = [
261
+ "aho-corasick",
262
+ "memchr",
263
+ "regex-syntax",
264
+ ]
265
+
266
+ [[package]]
267
+ name = "regex-syntax"
268
+ version = "0.8.6"
269
+ source = "registry+https://github.com/rust-lang/crates.io-index"
270
+ checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001"
271
+
272
+ [[package]]
273
+ name = "rustc-hash"
274
+ version = "1.1.0"
275
+ source = "registry+https://github.com/rust-lang/crates.io-index"
276
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
277
+
278
+ [[package]]
279
+ name = "ryu"
280
+ version = "1.0.20"
281
+ source = "registry+https://github.com/rust-lang/crates.io-index"
282
+ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
283
+
284
+ [[package]]
285
+ name = "seq-macro"
286
+ version = "0.3.6"
287
+ source = "registry+https://github.com/rust-lang/crates.io-index"
288
+ checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
289
+
290
+ [[package]]
291
+ name = "serde"
292
+ version = "1.0.225"
293
+ source = "registry+https://github.com/rust-lang/crates.io-index"
294
+ checksum = "fd6c24dee235d0da097043389623fb913daddf92c76e9f5a1db88607a0bcbd1d"
295
+ dependencies = [
296
+ "serde_core",
297
+ ]
298
+
299
+ [[package]]
300
+ name = "serde_core"
301
+ version = "1.0.225"
302
+ source = "registry+https://github.com/rust-lang/crates.io-index"
303
+ checksum = "659356f9a0cb1e529b24c01e43ad2bdf520ec4ceaf83047b83ddcc2251f96383"
304
+ dependencies = [
305
+ "serde_derive",
306
+ ]
307
+
308
+ [[package]]
309
+ name = "serde_derive"
310
+ version = "1.0.225"
311
+ source = "registry+https://github.com/rust-lang/crates.io-index"
312
+ checksum = "0ea936adf78b1f766949a4977b91d2f5595825bd6ec079aa9543ad2685fc4516"
313
+ dependencies = [
314
+ "proc-macro2",
315
+ "quote",
316
+ "syn",
317
+ ]
318
+
319
+ [[package]]
320
+ name = "shell-words"
321
+ version = "1.1.0"
322
+ source = "registry+https://github.com/rust-lang/crates.io-index"
323
+ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
324
+
325
+ [[package]]
326
+ name = "shlex"
327
+ version = "1.3.0"
328
+ source = "registry+https://github.com/rust-lang/crates.io-index"
329
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
330
+
331
+ [[package]]
332
+ name = "syn"
333
+ version = "2.0.106"
334
+ source = "registry+https://github.com/rust-lang/crates.io-index"
335
+ checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
336
+ dependencies = [
337
+ "proc-macro2",
338
+ "quote",
339
+ "unicode-ident",
340
+ ]
341
+
342
+ [[package]]
343
+ name = "unicode-ident"
344
+ version = "1.0.19"
345
+ source = "registry+https://github.com/rust-lang/crates.io-index"
346
+ checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
347
+
348
+ [[package]]
349
+ name = "windows-link"
350
+ version = "0.1.3"
351
+ source = "registry+https://github.com/rust-lang/crates.io-index"
352
+ checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
353
+
354
+ [[package]]
355
+ name = "windows-targets"
356
+ version = "0.53.3"
357
+ source = "registry+https://github.com/rust-lang/crates.io-index"
358
+ checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
359
+ dependencies = [
360
+ "windows-link",
361
+ "windows_aarch64_gnullvm",
362
+ "windows_aarch64_msvc",
363
+ "windows_i686_gnu",
364
+ "windows_i686_gnullvm",
365
+ "windows_i686_msvc",
366
+ "windows_x86_64_gnu",
367
+ "windows_x86_64_gnullvm",
368
+ "windows_x86_64_msvc",
369
+ ]
370
+
371
+ [[package]]
372
+ name = "windows_aarch64_gnullvm"
373
+ version = "0.53.0"
374
+ source = "registry+https://github.com/rust-lang/crates.io-index"
375
+ checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
376
+
377
+ [[package]]
378
+ name = "windows_aarch64_msvc"
379
+ version = "0.53.0"
380
+ source = "registry+https://github.com/rust-lang/crates.io-index"
381
+ checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
382
+
383
+ [[package]]
384
+ name = "windows_i686_gnu"
385
+ version = "0.53.0"
386
+ source = "registry+https://github.com/rust-lang/crates.io-index"
387
+ checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
388
+
389
+ [[package]]
390
+ name = "windows_i686_gnullvm"
391
+ version = "0.53.0"
392
+ source = "registry+https://github.com/rust-lang/crates.io-index"
393
+ checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
394
+
395
+ [[package]]
396
+ name = "windows_i686_msvc"
397
+ version = "0.53.0"
398
+ source = "registry+https://github.com/rust-lang/crates.io-index"
399
+ checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
400
+
401
+ [[package]]
402
+ name = "windows_x86_64_gnu"
403
+ version = "0.53.0"
404
+ source = "registry+https://github.com/rust-lang/crates.io-index"
405
+ checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
406
+
407
+ [[package]]
408
+ name = "windows_x86_64_gnullvm"
409
+ version = "0.53.0"
410
+ source = "registry+https://github.com/rust-lang/crates.io-index"
411
+ checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
412
+
413
+ [[package]]
414
+ name = "windows_x86_64_msvc"
415
+ version = "0.53.0"
416
+ source = "registry+https://github.com/rust-lang/crates.io-index"
417
+ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
data/Cargo.toml ADDED
@@ -0,0 +1,7 @@
1
+ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
2
+ # a Rust project. Your extensions dependencies should be added to the Cargo.toml
3
+ # in the ext/ directory.
4
+
5
+ [workspace]
6
+ members = ["./ext/r_csv"]
7
+ resolver = "2"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 fujitani sora
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,43 @@
1
+ # RCsv
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/r_csv`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/r_csv. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/r_csv/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the RCsv project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/r_csv/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,22 @@
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
+
12
+ require "rb_sys/extensiontask"
13
+
14
+ task build: :compile
15
+
16
+ GEMSPEC = Gem::Specification.load("rbcsv.gemspec")
17
+
18
+ RbSys::ExtensionTask.new("rbcsv", GEMSPEC) do |ext|
19
+ ext.lib_dir = "lib/rbcsv"
20
+ end
21
+
22
+ task default: %i[compile spec rubocop]
data/benchmark.rb ADDED
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'csv'
5
+ require 'benchmark'
6
+ require 'date'
7
+ require_relative 'lib/r_csv'
8
+
9
+ # CSV file path
10
+ CSV_FILE = 'sample.csv'
11
+
12
+ puts "=== CSV Library Benchmark Comparison ==="
13
+ puts "File: #{CSV_FILE}"
14
+ puts "Ruby version: #{RUBY_VERSION}"
15
+ puts
16
+
17
+ # Read CSV content once for string-based parsing
18
+ csv_content = File.read(CSV_FILE)
19
+ puts "File size: #{csv_content.bytesize} bytes"
20
+ puts "Records: #{CSV.read(CSV_FILE, headers: true).length}"
21
+ puts
22
+
23
+ puts "=== Parse Performance Comparison ==="
24
+ Benchmark.bm(35) do |x|
25
+
26
+ # Built-in CSV.read - bulk read with headers
27
+ x.report("CSV.read (headers: true)") do
28
+ 1000.times do
29
+ data = CSV.read(CSV_FILE, headers: true)
30
+ end
31
+ end
32
+
33
+ # Built-in CSV.parse - from string with headers
34
+ x.report("CSV.parse (headers: true)") do
35
+ 1000.times do
36
+ data = CSV.parse(csv_content, headers: true)
37
+ end
38
+ end
39
+
40
+ # Built-in CSV.parse - raw parsing
41
+ x.report("CSV.parse (raw)") do
42
+ 1000.times do
43
+ data = CSV.parse(csv_content)
44
+ end
45
+ end
46
+
47
+ # r_csv - Rust extension parsing
48
+ x.report("RCsv.parse (Rust)") do
49
+ 1000.times do
50
+ data = RCsv.parse(csv_content)
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ puts "\n=== Memory Usage Comparison ==="
57
+
58
+ # Helper to measure memory usage
59
+ def memory_usage
60
+ `ps -o rss= -p #{Process.pid}`.to_i
61
+ end
62
+
63
+ puts "Initial memory usage: #{memory_usage} KB"
64
+
65
+ # CSV.read
66
+ before_read = memory_usage
67
+ data_read = CSV.read(CSV_FILE, headers: true)
68
+ after_read = memory_usage
69
+ puts "After CSV.read: #{after_read} KB (diff: #{after_read - before_read} KB)"
70
+
71
+ # CSV.parse
72
+ before_parse = memory_usage
73
+ data_parse = CSV.parse(csv_content)
74
+ after_parse = memory_usage
75
+ puts "After CSV.parse: #{after_parse} KB (diff: #{after_parse - before_parse} KB)"
76
+
77
+ # r_csv
78
+ before_rcv = memory_usage
79
+ data_rcv = RCsv.parse(csv_content)
80
+ after_rcv = memory_usage
81
+ puts "After RCsv.parse: #{after_rcv} KB (diff: #{after_rcv - before_parse} KB)"
82
+
83
+ puts "\n=== Data Accuracy Verification ==="
84
+ puts "CSV.read rows: #{data_read.length}"
85
+ puts "CSV.parse rows: #{data_parse.length}"
86
+ puts "RCsv.parse rows: #{data_rcv.length}"
87
+
88
+ # Verify first row data
89
+ if data_rcv.length > 0
90
+ puts "\nFirst row comparison:"
91
+ puts "CSV.read: #{data_read.first.fields}"
92
+ puts "CSV.parse: #{data_parse[1]}" # Skip header
93
+ puts "RCsv.parse: #{data_rcv[0]}"
94
+ end
95
+
96
+ puts "\n=== Large Data Simulation ==="
97
+ puts "Generating 10,000 records for benchmark..."
98
+
99
+ # Generate large data
100
+ large_csv_file = 'large_sample.csv'
101
+ CSV.open(large_csv_file, "w") do |csv|
102
+ # Write header
103
+ csv << data_read.first.headers
104
+
105
+ # Duplicate original data 100 times
106
+ 100.times do |batch|
107
+ data_read.each_with_index do |row, index|
108
+ new_row = row.fields.dup
109
+ new_row[0] = (batch * 100 + index + 1).to_s # Update ID
110
+ csv << new_row
111
+ end
112
+ end
113
+ end
114
+
115
+ large_csv_content = File.read(large_csv_file)
116
+ puts "Large data file created: #{File.size(large_csv_file)} bytes"
117
+
118
+ # Large data benchmark
119
+ puts "\n=== Large Data Performance Test ==="
120
+ Benchmark.bm(35) do |x|
121
+
122
+ x.report("CSV.read (large, 10 times)") do
123
+ 10.times do
124
+ large_data = CSV.read(large_csv_file, headers: true)
125
+ end
126
+ end
127
+
128
+ x.report("CSV.parse (large, 10 times)") do
129
+ 10.times do
130
+ large_data = CSV.parse(large_csv_content, headers: true)
131
+ end
132
+ end
133
+
134
+ x.report("RCsv.parse (large, 10 times)") do
135
+ 10.times do
136
+ large_data = RCsv.parse(large_csv_content)
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ puts "\n=== Processing Speed Comparison ==="
143
+ csv_data = CSV.parse(csv_content, headers: true)
144
+ rcv_data = RCsv.parse(csv_content)
145
+
146
+ Benchmark.bm(35) do |x|
147
+
148
+ # Search by category with CSV data
149
+ x.report("CSV search 'tech' (1000x)") do
150
+ 1000.times do
151
+ csv_data.select { |row| row['category'] == 'tech' }
152
+ end
153
+ end
154
+
155
+ # Search by category with r_csv data (need to implement indexing)
156
+ x.report("RCsv search 'tech' (1000x)") do
157
+ 1000.times do
158
+ rcv_data.select { |row| row[3] == 'tech' } # category is 4th column (index 3)
159
+ end
160
+ end
161
+
162
+ # Complex filtering with CSV
163
+ x.report("CSV complex filter (1000x)") do
164
+ 1000.times do
165
+ csv_data.select { |row|
166
+ row['category'] == 'tech' && row['status'] == 'published'
167
+ }
168
+ end
169
+ end
170
+
171
+ # Complex filtering with r_csv
172
+ x.report("RCsv complex filter (1000x)") do
173
+ 1000.times do
174
+ rcv_data.select { |row|
175
+ row[3] == 'tech' && row[4] == 'published'
176
+ }
177
+ end
178
+ end
179
+
180
+ end
181
+
182
+ # Cleanup
183
+ File.delete(large_csv_file)
184
+
185
+ puts "\n=== Performance Summary ==="
186
+ puts "r_csv provides raw array data (faster for pure parsing)"
187
+ puts "CSV provides structured data with headers (better for development)"
188
+ puts "Choose based on your use case: speed vs convenience"
189
+ puts "\n=== Benchmark Complete ==="
190
+ puts "Execution time: #{Time.now}"