Commit 52a36f8
committed
GH-49656: [Ruby] Add benchmark for writers
Performance is important in Apache Arrow. So benchmark is useful for
developing Apache Arrow implementation.
* Add benchmarks for file and streaming writers.
* Remove redundant type arguments from array constructors.
Here are benchmark results on my environment.
Pure Ruby implementation is about 2-2.5x slower than release build C++
implementation but about 2-2.5x faster than debug build C++
implementation.
Release build C++/GLib:
File format:
```console
$ ruby -v -S benchmark-driver ruby/red-arrow-format/benchmark/file-writer.yaml
ruby 4.1.0dev (2026-03-26T07:27:31Z master c5ab2114df) +PRISM [x86_64-linux]
Warming up --------------------------------------
Arrow::Table#save 348.499 i/s - 374.000 times in 1.073175s (2.87ms/i)
Arrow::RecordBatchFileWriter 353.426 i/s - 385.000 times in 1.089337s (2.83ms/i)
ArrowFormat::FileWriter 133.293 i/s - 140.000 times in 1.050314s (7.50ms/i)
Calculating -------------------------------------
Arrow::Table#save 336.984 i/s - 1.045k times in 3.101035s (2.97ms/i)
Arrow::RecordBatchFileWriter 338.695 i/s - 1.060k times in 3.129655s (2.95ms/i)
ArrowFormat::FileWriter 134.640 i/s - 399.000 times in 2.963462s (7.43ms/i)
Comparison:
Arrow::RecordBatchFileWriter: 338.7 i/s
Arrow::Table#save: 337.0 i/s - 1.01x slower
ArrowFormat::FileWriter: 134.6 i/s - 2.52x slower
```
Streaming format:
```console
$ ruby -v -S benchmark-driver ruby/red-arrow-format/benchmark/streaming-writer.yaml
ruby 4.1.0dev (2026-03-26T07:27:31Z master c5ab2114df) +PRISM [x86_64-linux]
Warming up --------------------------------------
Arrow::Table#save 356.995 i/s - 385.000 times in 1.078447s (2.80ms/i)
Arrow::RecordBatchStreamWriter 347.891 i/s - 374.000 times in 1.075050s (2.87ms/i)
ArrowFormat::StreamingWriter 156.709 i/s - 160.000 times in 1.021004s (6.38ms/i)
Calculating -------------------------------------
Arrow::Table#save 350.743 i/s - 1.070k times in 3.050665s (2.85ms/i)
Arrow::RecordBatchStreamWriter 345.821 i/s - 1.043k times in 3.016011s (2.89ms/i)
ArrowFormat::StreamingWriter 160.022 i/s - 470.000 times in 2.937090s (6.25ms/i)
Comparison:
Arrow::Table#save: 350.7 i/s
Arrow::RecordBatchStreamWriter: 345.8 i/s - 1.01x slower
ArrowFormat::StreamingWriter: 160.0 i/s - 2.19x slower
```
Debug build C++/GLib:
File format:
```console
$ ruby -v -S benchmark-driver ruby/red-arrow-format/benchmark/file-writer.yaml
ruby 4.1.0dev (2026-03-26T07:27:31Z master c5ab2114df) +PRISM [x86_64-linux]
Warming up --------------------------------------
Arrow::Table#save 63.290 i/s - 66.000 times in 1.042815s (15.80ms/i)
Arrow::RecordBatchFileWriter 62.655 i/s - 66.000 times in 1.053389s (15.96ms/i)
ArrowFormat::FileWriter 138.082 i/s - 140.000 times in 1.013891s (7.24ms/i)
Calculating -------------------------------------
Arrow::Table#save 63.165 i/s - 189.000 times in 2.992143s (15.83ms/i)
Arrow::RecordBatchFileWriter 61.773 i/s - 187.000 times in 3.027220s (16.19ms/i)
ArrowFormat::FileWriter 134.709 i/s - 414.000 times in 3.073285s (7.42ms/i)
Comparison:
ArrowFormat::FileWriter: 134.7 i/s
Arrow::Table#save: 63.2 i/s - 2.13x slower
Arrow::RecordBatchFileWriter: 61.8 i/s - 2.18x slower
```
Streaming format:
```console
$ ruby -v -S benchmark-driver ruby/red-arrow-format/benchmark/streaming-writer.yaml
ruby 4.1.0dev (2026-03-26T07:27:31Z master c5ab2114df) +PRISM [x86_64-linux]
Warming up --------------------------------------
Arrow::Table#save 63.252 i/s - 66.000 times in 1.043439s (15.81ms/i)
Arrow::RecordBatchStreamWriter 61.272 i/s - 66.000 times in 1.077162s (16.32ms/i)
ArrowFormat::StreamingWriter 152.598 i/s - 160.000 times in 1.048506s (6.55ms/i)
Calculating -------------------------------------
Arrow::Table#save 61.016 i/s - 189.000 times in 3.097525s (16.39ms/i)
Arrow::RecordBatchStreamWriter 63.024 i/s - 183.000 times in 2.903642s (15.87ms/i)
ArrowFormat::StreamingWriter 160.416 i/s - 457.000 times in 2.848846s (6.23ms/i)
Comparison:
ArrowFormat::StreamingWriter: 160.4 i/s
Arrow::RecordBatchStreamWriter: 63.0 i/s - 2.55x slower
Arrow::Table#save: 61.0 i/s - 2.63x slower
```1 parent ddc4229 commit 52a36f8
File tree
4 files changed
+293
-25
lines changed- ruby/red-arrow-format
- benchmark
- lib/arrow-format
4 files changed
+293
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
144 | | - | |
| 143 | + | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
189 | 193 | | |
190 | 194 | | |
191 | 195 | | |
| |||
209 | 213 | | |
210 | 214 | | |
211 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
212 | 219 | | |
213 | 220 | | |
214 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
215 | 227 | | |
216 | 228 | | |
217 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
218 | 235 | | |
219 | 236 | | |
220 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
221 | 243 | | |
222 | 244 | | |
223 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
224 | 251 | | |
225 | 252 | | |
226 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
227 | 259 | | |
228 | 260 | | |
229 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
230 | 267 | | |
231 | 268 | | |
232 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
233 | 275 | | |
234 | 276 | | |
235 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
236 | 283 | | |
237 | 284 | | |
238 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
239 | 289 | | |
240 | 290 | | |
241 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
242 | 297 | | |
243 | 298 | | |
244 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
245 | 305 | | |
246 | 306 | | |
247 | 307 | | |
248 | 308 | | |
249 | 309 | | |
250 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
251 | 314 | | |
252 | 315 | | |
253 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
254 | 322 | | |
255 | 323 | | |
256 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
257 | 330 | | |
258 | 331 | | |
259 | 332 | | |
| |||
318 | 391 | | |
319 | 392 | | |
320 | 393 | | |
321 | | - | |
322 | | - | |
| 394 | + | |
| 395 | + | |
323 | 396 | | |
324 | 397 | | |
325 | 398 | | |
| |||
364 | 437 | | |
365 | 438 | | |
366 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
367 | 445 | | |
368 | 446 | | |
369 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
370 | 453 | | |
371 | 454 | | |
372 | 455 | | |
373 | 456 | | |
374 | 457 | | |
375 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
376 | 464 | | |
377 | 465 | | |
378 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
379 | 472 | | |
380 | 473 | | |
381 | 474 | | |
| |||
0 commit comments