forked from fastruby/fast-ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ruby-3.1.5.fastruby
922 lines (800 loc) · 40.2 KB
/
ruby-3.1.5.fastruby
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
$ ruby -v code/general/array-argument-vs-splat-arguments.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Function with single Array argument
769.207k i/100ms
Function with splat arguments
29.213k i/100ms
Calculating -------------------------------------
Function with single Array argument
7.676M (± 2.2%) i/s - 38.460M in 5.013342s
Function with splat arguments
286.387k (± 5.7%) i/s - 1.431M in 5.022041s
Comparison:
Function with single Array argument: 7675659.8 i/s
Function with splat arguments: 286387.2 i/s - 26.80x (± 0.00) slower
$ ruby -v code/general/assignment.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Parallel Assignment 1.018M i/100ms
Sequential Assignment
1.008M i/100ms
Calculating -------------------------------------
Parallel Assignment 10.202M (± 0.3%) i/s - 51.914M in 5.088798s
Sequential Assignment
10.138M (± 0.3%) i/s - 51.425M in 5.072563s
Comparison:
Parallel Assignment: 10201724.6 i/s
Sequential Assignment: 10138073.2 i/s - 1.01x (± 0.00) slower
$ ruby -v code/general/attr-accessor-vs-getter-and-setter.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
getter_and_setter 484.770k i/100ms
attr_accessor 538.074k i/100ms
Calculating -------------------------------------
getter_and_setter 4.850M (± 0.3%) i/s - 24.723M in 5.098024s
attr_accessor 5.339M (± 0.3%) i/s - 26.904M in 5.039561s
Comparison:
attr_accessor: 5338564.2 i/s
getter_and_setter: 4849616.9 i/s - 1.10x (± 0.00) slower
$ ruby -v code/general/begin-rescue-vs-respond-to.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
begin...rescue 88.421k i/100ms
respond_to? 776.566k i/100ms
Calculating -------------------------------------
begin...rescue 886.944k (± 0.6%) i/s - 4.509M in 5.084452s
respond_to? 7.716M (± 1.9%) i/s - 38.828M in 5.034436s
Comparison:
respond_to?: 7715677.9 i/s
begin...rescue: 886944.4 i/s - 8.70x (± 0.00) slower
$ ruby -v code/general/block-apply-method.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
normal 318.999k i/100ms
&method 123.802k i/100ms
Calculating -------------------------------------
normal 3.188M (± 0.4%) i/s - 15.950M in 5.002531s
&method 1.251M (± 0.6%) i/s - 6.314M in 5.048218s
Comparison:
normal: 3188430.1 i/s
&method: 1250762.5 i/s - 2.55x (± 0.00) slower
$ ruby -v code/general/define_method-vs-module-eval.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
module_eval with string
268.000 i/100ms
define_method 288.000 i/100ms
Calculating -------------------------------------
module_eval with string
2.389k (±20.4%) i/s - 10.720k in 5.092004s
define_method 3.226k (±19.0%) i/s - 14.688k in 5.035044s
Comparison:
define_method: 3225.8 i/s
module_eval with string: 2389.3 i/s - same-ish: difference falls within error
$ ruby -v code/general/format-vs-round-and-to-s.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Float#round 260.524k i/100ms
Kernel#format 199.189k i/100ms
String#% 171.362k i/100ms
Calculating -------------------------------------
Float#round 2.599M (± 0.8%) i/s - 13.026M in 5.012016s
Kernel#format 1.997M (± 0.4%) i/s - 10.159M in 5.087304s
String#% 1.714M (± 0.3%) i/s - 8.739M in 5.098777s
Comparison:
Float#round: 2599160.2 i/s
Kernel#format: 1996895.1 i/s - 1.30x (± 0.00) slower
String#%: 1714051.5 i/s - 1.52x (± 0.00) slower
$ ruby -v code/general/hash-vs-openstruct-on-access.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash 880.736k i/100ms
OpenStruct 477.095k i/100ms
Calculating -------------------------------------
Hash 8.936M (± 0.3%) i/s - 44.918M in 5.026875s
OpenStruct 4.764M (± 1.0%) i/s - 23.855M in 5.008318s
Comparison:
Hash: 8935557.2 i/s
OpenStruct: 4763552.4 i/s - 1.88x (± 0.00) slower
$ ruby -v code/general/hash-vs-openstruct.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash 1.100M i/100ms
OpenStruct 11.661k i/100ms
Calculating -------------------------------------
Hash 11.635M (± 2.0%) i/s - 58.309M in 5.013769s
OpenStruct 116.976k (± 2.5%) i/s - 594.711k in 5.087150s
Comparison:
Hash: 11634881.2 i/s
OpenStruct: 116975.7 i/s - 99.46x (± 0.00) slower
$ ruby -v code/general/inheritance-check.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
less than or equal 587.036k i/100ms
ancestors.include? 120.178k i/100ms
Calculating -------------------------------------
less than or equal 5.777M (± 1.6%) i/s - 29.352M in 5.082142s
ancestors.include? 1.186M (± 0.6%) i/s - 6.009M in 5.067471s
Comparison:
less than or equal: 5776913.1 i/s
ancestors.include?: 1185815.9 i/s - 4.87x (± 0.00) slower
$ ruby -v code/general/loop-vs-while-true.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
While Loop 1.000 i/100ms
Kernel loop 1.000 i/100ms
Calculating -------------------------------------
While Loop 0.638 (± 0.0%) i/s - 4.000 in 6.270106s
Kernel loop 0.228 (± 0.0%) i/s - 2.000 in 8.778109s
Comparison:
While Loop: 0.6 i/s
Kernel loop: 0.2 i/s - 2.80x (± 0.00) slower
$ ruby -v code/general/raise-vs-e2mmap.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
$ ruby -v code/array/array-first-vs-index.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Array#[0] 1.555M i/100ms
Array#first 1.311M i/100ms
Calculating -------------------------------------
Array#[0] 15.573M (± 0.2%) i/s - 79.322M in 5.093469s
Array#first 13.268M (± 0.3%) i/s - 66.873M in 5.040303s
Comparison:
Array#[0]: 15573254.2 i/s
Array#first: 13267805.7 i/s - 1.17x (± 0.00) slower
$ ruby -v code/array/array-last-vs-index.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Array#[-1] 1.556M i/100ms
Array#last 1.331M i/100ms
Calculating -------------------------------------
Array#[-1] 15.576M (± 0.3%) i/s - 79.350M in 5.094513s
Array#last 13.300M (± 0.3%) i/s - 66.565M in 5.004973s
Comparison:
Array#[-1]: 15575778.0 i/s
Array#last: 13299944.6 i/s - 1.17x (± 0.00) slower
$ ruby -v code/array/bsearch-vs-find.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
find 1.000 i/100ms
bsearch 99.170k i/100ms
Calculating -------------------------------------
find 0.271 (± 0.0%) i/s - 2.000 in 7.377899s
bsearch 995.889k (± 0.3%) i/s - 5.058M in 5.078585s
Comparison:
bsearch: 995889.0 i/s
find: 0.3 i/s - 3673780.16x (± 0.00) slower
$ ruby -v code/array/insert-vs-unshift.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Array#unshift 19.000 i/100ms
Array#insert 1.000 i/100ms
Calculating -------------------------------------
Array#unshift 195.309 (± 2.6%) i/s - 988.000 in 5.062069s
Array#insert 1.451 (± 0.0%) i/s - 8.000 in 5.512996s
Comparison:
Array#unshift: 195.3 i/s
Array#insert: 1.5 i/s - 134.59x (± 0.00) slower
$ ruby -v code/array/length-vs-size-vs-count.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Array#length 2.092M i/100ms
Array#size 2.096M i/100ms
Array#count 1.622M i/100ms
Calculating -------------------------------------
Array#length 20.844M (± 0.5%) i/s - 104.622M in 5.019458s
Array#size 20.991M (± 0.4%) i/s - 106.880M in 5.091842s
Array#count 16.231M (± 0.4%) i/s - 82.735M in 5.097397s
Comparison:
Array#size: 20990875.0 i/s
Array#length: 20843669.7 i/s - same-ish: difference falls within error
Array#count: 16231073.1 i/s - 1.29x (± 0.00) slower
$ ruby -v code/array/shuffle-first-vs-sample.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Array#shuffle.first 46.193k i/100ms
Array#sample 1.008M i/100ms
Calculating -------------------------------------
Array#shuffle.first 463.891k (± 0.5%) i/s - 2.356M in 5.078589s
Array#sample 10.067M (± 0.4%) i/s - 50.409M in 5.007390s
Comparison:
Array#sample: 10067002.1 i/s
Array#shuffle.first: 463890.8 i/s - 21.70x (± 0.00) slower
$ ruby -v code/date/iso8601-vs-parse.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Date.iso8601 63.630k i/100ms
Date.parse 32.455k i/100ms
Calculating -------------------------------------
Date.iso8601 643.273k (± 0.5%) i/s - 3.245M in 5.044863s
Date.parse 324.180k (± 0.5%) i/s - 1.623M in 5.005829s
Comparison:
Date.iso8601: 643272.9 i/s
Date.parse: 324180.3 i/s - 1.98x (± 0.00) slower
$ ruby -v code/enumerable/each-push-vs-map.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Array#each + push 19.099k i/100ms
Array#map 26.180k i/100ms
Calculating -------------------------------------
Array#each + push 189.174k (± 0.6%) i/s - 954.950k in 5.048160s
Array#map 261.157k (± 1.2%) i/s - 1.309M in 5.013058s
Comparison:
Array#map: 261157.0 i/s
Array#each + push: 189174.1 i/s - 1.38x (± 0.00) slower
$ ruby -v code/enumerable/each-vs-for-loop.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
For loop 29.534k i/100ms
#each 32.604k i/100ms
Calculating -------------------------------------
For loop 297.087k (± 0.5%) i/s - 1.506M in 5.070134s
#each 326.327k (± 0.4%) i/s - 1.663M in 5.095580s
Comparison:
#each: 326326.9 i/s
For loop: 297086.6 i/s - 1.10x (± 0.00) slower
$ ruby -v code/enumerable/each_with_index-vs-while-loop.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
While Loop 27.551k i/100ms
each_with_index 19.385k i/100ms
Calculating -------------------------------------
While Loop 274.029k (± 0.2%) i/s - 1.378M in 5.027046s
each_with_index 194.400k (± 0.2%) i/s - 988.635k in 5.085596s
Comparison:
While Loop: 274028.6 i/s
each_with_index: 194400.0 i/s - 1.41x (± 0.00) slower
$ ruby -v code/enumerable/inject-symbol-vs-block.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
inject symbol 123.975k i/100ms
inject to_proc 2.145k i/100ms
inject block 2.146k i/100ms
Calculating -------------------------------------
inject symbol 1.036M (±15.7%) i/s - 5.083M in 5.014872s
inject to_proc 21.869k (± 3.3%) i/s - 109.395k in 5.008339s
inject block 21.522k (± 0.4%) i/s - 109.446k in 5.085501s
Comparison:
inject symbol: 1035927.4 i/s
inject to_proc: 21869.3 i/s - 47.37x (± 0.00) slower
inject block: 21521.6 i/s - 48.13x (± 0.00) slower
$ ruby -v code/enumerable/map-flatten-vs-flat_map.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Array#map.flatten(1) 6.991k i/100ms
Array#map.flatten 4.006k i/100ms
Array#flat_map 9.710k i/100ms
Calculating -------------------------------------
Array#map.flatten(1) 69.537k (± 0.7%) i/s - 349.550k in 5.027100s
Array#map.flatten 40.103k (± 0.2%) i/s - 204.306k in 5.094599s
Array#flat_map 96.767k (± 0.3%) i/s - 485.500k in 5.017256s
Comparison:
Array#flat_map: 96766.7 i/s
Array#map.flatten(1): 69536.6 i/s - 1.39x (± 0.00) slower
Array#map.flatten: 40102.7 i/s - 2.41x (± 0.00) slower
$ ruby -v code/enumerable/reverse-each-vs-reverse_each.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Array#reverse.each 31.688k i/100ms
Array#reverse_each 32.554k i/100ms
Calculating -------------------------------------
Array#reverse.each 317.420k (± 0.5%) i/s - 1.616M in 5.091465s
Array#reverse_each 325.731k (± 0.4%) i/s - 1.660M in 5.097111s
Comparison:
Array#reverse_each: 325730.6 i/s
Array#reverse.each: 317419.8 i/s - 1.03x (± 0.00) slower
$ ruby -v code/enumerable/select-first-vs-detect.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Enumerable#select.first
20.899k i/100ms
Enumerable#detect 82.562k i/100ms
Calculating -------------------------------------
Enumerable#select.first
210.128k (± 0.3%) i/s - 4.222M in 20.090883s
Enumerable#detect 833.988k (± 0.9%) i/s - 16.760M in 20.097918s
Comparison:
Enumerable#detect: 833988.1 i/s
Enumerable#select.first: 210127.6 i/s - 3.97x (± 0.00) slower
$ ruby -v code/enumerable/select-last-vs-reverse-detect.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Enumerable#reverse.detect
244.217k i/100ms
Enumerable#select.last
19.159k i/100ms
Calculating -------------------------------------
Enumerable#reverse.detect
2.439M (± 0.4%) i/s - 12.211M in 5.006017s
Enumerable#select.last
190.351k (± 0.3%) i/s - 957.950k in 5.032609s
Comparison:
Enumerable#reverse.detect: 2439276.6 i/s
Enumerable#select.last: 190350.8 i/s - 12.81x (± 0.00) slower
$ ruby -v code/enumerable/sort-vs-sort_by.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Enumerable#sort_by (Symbol#to_proc)
5.017k i/100ms
Enumerable#sort_by 4.795k i/100ms
Enumerable#sort 2.405k i/100ms
Calculating -------------------------------------
Enumerable#sort_by (Symbol#to_proc)
50.570k (± 5.0%) i/s - 255.867k in 5.078155s
Enumerable#sort_by 48.534k (± 1.5%) i/s - 244.545k in 5.039871s
Enumerable#sort 23.954k (± 0.8%) i/s - 120.250k in 5.020308s
Comparison:
Enumerable#sort_by (Symbol#to_proc): 50570.4 i/s
Enumerable#sort_by: 48533.7 i/s - same-ish: difference falls within error
Enumerable#sort: 23954.3 i/s - 2.11x (± 0.00) slower
$ ruby -v code/enumerable/sort_by-first-vs-min_by.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Enumerable#min_by 17.555k i/100ms
Enumerable#sort_by...first
8.996k i/100ms
Calculating -------------------------------------
Enumerable#min_by 175.411k (± 1.0%) i/s - 877.750k in 5.004464s
Enumerable#sort_by...first
89.763k (± 0.6%) i/s - 449.800k in 5.011113s
Comparison:
Enumerable#min_by: 175410.9 i/s
Enumerable#sort_by...first: 89763.3 i/s - 1.95x (± 0.00) slower
$ ruby -v code/hash/bracket-vs-dup.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash[] 398.265k i/100ms
Hash#dup 287.560k i/100ms
Calculating -------------------------------------
Hash[] 3.587M (± 0.5%) i/s - 18.320M in 5.107560s
Hash#dup 2.943M (± 1.1%) i/s - 14.953M in 5.081100s
Comparison:
Hash[]: 3586967.3 i/s
Hash#dup: 2943261.3 i/s - 1.22x (± 0.00) slower
$ ruby -v code/hash/bracket-vs-fetch.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#[], symbol 1.371M i/100ms
Hash#fetch, symbol 1.182M i/100ms
Hash#[], string 1.216M i/100ms
Hash#fetch, string 785.753k i/100ms
Calculating -------------------------------------
Hash#[], symbol 13.699M (± 0.5%) i/s - 68.556M in 5.004452s
Hash#fetch, symbol 11.815M (± 0.4%) i/s - 59.077M in 5.000296s
Hash#[], string 12.169M (± 0.4%) i/s - 62.034M in 5.097597s
Hash#fetch, string 7.821M (± 0.7%) i/s - 39.288M in 5.023334s
Comparison:
Hash#[], symbol: 13699278.1 i/s
Hash#[], string: 12169460.7 i/s - 1.13x (± 0.00) slower
Hash#fetch, symbol: 11814862.1 i/s - 1.16x (± 0.00) slower
Hash#fetch, string: 7821401.5 i/s - 1.75x (± 0.00) slower
$ ruby -v code/hash/dig-vs-[]-vs-fetch.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#dig 868.672k i/100ms
Hash#[] 1.008M i/100ms
Hash#[] || 890.064k i/100ms
Hash#[] && 391.101k i/100ms
Hash#fetch 589.233k i/100ms
Hash#fetch fallback 391.624k i/100ms
Calculating -------------------------------------
Hash#dig 8.565M (± 1.0%) i/s - 43.434M in 5.071599s
Hash#[] 10.408M (± 1.2%) i/s - 52.437M in 5.038915s
Hash#[] || 9.325M (± 0.7%) i/s - 47.173M in 5.059031s
Hash#[] && 4.245M (± 1.9%) i/s - 21.511M in 5.069593s
Hash#fetch 5.928M (± 0.9%) i/s - 30.051M in 5.069478s
Hash#fetch fallback 3.912M (± 0.8%) i/s - 19.581M in 5.005591s
Comparison:
Hash#[]: 10407980.4 i/s
Hash#[] ||: 9325086.8 i/s - 1.12x (± 0.00) slower
Hash#dig: 8564927.1 i/s - 1.22x (± 0.00) slower
Hash#fetch: 5928268.2 i/s - 1.76x (± 0.00) slower
Hash#[] &&: 4244566.7 i/s - 2.45x (± 0.00) slower
Hash#fetch fallback: 3912117.5 i/s - 2.66x (± 0.00) slower
$ ruby -v code/hash/fetch-vs-fetch-with-block.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#fetch + const 1.446M i/100ms
Hash#fetch + block 1.455M i/100ms
Hash#fetch + arg 1.098M i/100ms
Calculating -------------------------------------
Hash#fetch + const 14.530M (± 0.5%) i/s - 73.753M in 5.076096s
Hash#fetch + block 14.652M (± 0.5%) i/s - 74.202M in 5.064299s
Hash#fetch + arg 10.970M (± 0.3%) i/s - 54.902M in 5.004896s
Comparison:
Hash#fetch + block: 14652301.9 i/s
Hash#fetch + const: 14529817.0 i/s - same-ish: difference falls within error
Hash#fetch + arg: 10969739.5 i/s - 1.34x (± 0.00) slower
$ ruby -v code/hash/hash-key-sort_by-vs-sort.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
sort_by + to_h 28.100k i/100ms
sort + to_h 11.685k i/100ms
Calculating -------------------------------------
sort_by + to_h 281.718k (± 0.6%) i/s - 1.433M in 5.087221s
sort + to_h 116.735k (± 1.3%) i/s - 584.250k in 5.005822s
Comparison:
sort_by + to_h: 281717.8 i/s
sort + to_h: 116735.5 i/s - 2.41x (± 0.00) slower
$ ruby -v code/hash/keys-each-vs-each_key.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#keys.each 192.953k i/100ms
Hash#each_key 204.248k i/100ms
Calculating -------------------------------------
Hash#keys.each 1.954M (± 0.9%) i/s - 9.841M in 5.035247s
Hash#each_key 2.042M (± 0.2%) i/s - 10.212M in 5.000431s
Comparison:
Hash#each_key: 2042316.1 i/s
Hash#keys.each: 1954492.1 i/s - 1.04x (± 0.00) slower
$ ruby -v code/hash/keys-include-vs-key.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#keys.include? 1.240k i/100ms
Hash#key? 994.635k i/100ms
Calculating -------------------------------------
Hash#keys.include? 12.295k (± 4.1%) i/s - 62.000k in 5.052661s
Hash#key? 9.936M (± 0.6%) i/s - 49.732M in 5.005283s
Comparison:
Hash#key?: 9936236.0 i/s
Hash#keys.include?: 12294.8 i/s - 808.17x (± 0.00) slower
$ ruby -v code/hash/merge-bang-vs-[]=.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#merge! 4.000k i/100ms
Hash#[]= 10.593k i/100ms
Calculating -------------------------------------
Hash#merge! 39.749k (± 0.3%) i/s - 200.000k in 5.031667s
Hash#[]= 105.564k (± 0.9%) i/s - 529.650k in 5.017703s
Comparison:
Hash#[]=: 105564.3 i/s
Hash#merge!: 39748.6 i/s - 2.66x (± 0.00) slower
$ ruby -v code/hash/merge-bang-vs-merge-vs-dup-merge-bang.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
{}#merge!(Hash) do end
4.768k i/100ms
Hash#merge({}) 3.996k i/100ms
Hash#dup#merge!({}) 2.913k i/100ms
Calculating -------------------------------------
{}#merge!(Hash) do end
48.010k (± 1.3%) i/s - 243.168k in 5.065780s
Hash#merge({}) 39.558k (± 0.5%) i/s - 199.800k in 5.050894s
Hash#dup#merge!({}) 28.926k (± 0.5%) i/s - 145.650k in 5.035356s
Comparison:
{}#merge!(Hash) do end: 48010.0 i/s
Hash#merge({}): 39558.4 i/s - 1.21x (± 0.00) slower
Hash#dup#merge!({}): 28926.2 i/s - 1.66x (± 0.00) slower
$ ruby -v code/hash/merge-vs-double-splat-operator.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#**other 396.488k i/100ms
Hash#merge 369.724k i/100ms
Calculating -------------------------------------
Hash#**other 3.939M (± 0.5%) i/s - 19.824M in 5.033417s
Hash#merge 3.700M (± 0.7%) i/s - 18.856M in 5.096513s
Comparison:
Hash#**other: 3938662.3 i/s
Hash#merge: 3699930.1 i/s - 1.06x (± 0.00) slower
$ ruby -v code/hash/merge-vs-merge-bang.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#merge 1.681k i/100ms
Hash#merge! 3.935k i/100ms
Calculating -------------------------------------
Hash#merge 16.589k (± 1.0%) i/s - 84.050k in 5.067202s
Hash#merge! 39.399k (± 0.8%) i/s - 200.685k in 5.093977s
Comparison:
Hash#merge!: 39398.8 i/s
Hash#merge: 16588.8 i/s - 2.38x (± 0.00) slower
$ ruby -v code/hash/slice-native-vs-before-native.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#native-slice 418.301k i/100ms
Array#each 225.726k i/100ms
Array#each_w/_object 176.553k i/100ms
Hash#select-include 72.040k i/100ms
Calculating -------------------------------------
Hash#native-slice 4.224M (± 0.7%) i/s - 21.333M in 5.051053s
Array#each 2.277M (± 0.5%) i/s - 11.512M in 5.055058s
Array#each_w/_object 1.770M (± 0.4%) i/s - 9.004M in 5.086637s
Hash#select-include 720.522k (± 0.4%) i/s - 3.674M in 5.099231s
Comparison:
Hash#native-slice : 4223748.2 i/s
Array#each : 2277384.8 i/s - 1.85x (± 0.00) slower
Array#each_w/_object: 1770193.1 i/s - 2.39x (± 0.00) slower
Hash#select-include : 720521.7 i/s - 5.86x (± 0.00) slower
$ ruby -v code/hash/values-include-vs-value.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Hash#values.include? 1.090k i/100ms
Hash#value? 845.000 i/100ms
Calculating -------------------------------------
Hash#values.include? 10.819k (± 3.7%) i/s - 54.500k in 5.045284s
Hash#value? 8.444k (± 0.6%) i/s - 42.250k in 5.003645s
Comparison:
Hash#values.include?: 10819.1 i/s
Hash#value?: 8444.2 i/s - 1.28x (± 0.00) slower
$ ruby -v code/method/call-vs-send-vs-method_missing.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
call 668.437k i/100ms
send 524.823k i/100ms
method_missing 392.124k i/100ms
Calculating -------------------------------------
call 6.667M (± 0.4%) i/s - 33.422M in 5.012881s
send 5.220M (± 0.4%) i/s - 26.241M in 5.027585s
method_missing 3.889M (± 0.5%) i/s - 19.606M in 5.041347s
Comparison:
call: 6667316.0 i/s
send: 5219524.2 i/s - 1.28x (± 0.00) slower
method_missing: 3889186.8 i/s - 1.71x (± 0.00) slower
$ ruby -v code/proc-and-block/block-vs-to_proc.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Block 9.056k i/100ms
Symbol#to_proc 10.279k i/100ms
Calculating -------------------------------------
Block 90.929k (± 0.4%) i/s - 461.856k in 5.079428s
Symbol#to_proc 102.176k (± 0.3%) i/s - 513.950k in 5.030125s
Comparison:
Symbol#to_proc: 102175.5 i/s
Block: 90928.5 i/s - 1.12x (± 0.00) slower
$ ruby -v code/proc-and-block/proc-call-vs-yield.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
block.call 946.228k i/100ms
block + yield 987.925k i/100ms
unused block 1.291M i/100ms
yield 1.178M i/100ms
Calculating -------------------------------------
block.call 9.463M (± 0.3%) i/s - 48.258M in 5.099534s
block + yield 9.886M (± 0.4%) i/s - 50.384M in 5.096567s
unused block 12.926M (± 0.3%) i/s - 65.833M in 5.093143s
yield 11.787M (± 0.3%) i/s - 60.083M in 5.097596s
Comparison:
unused block: 12925925.5 i/s
yield: 11786568.0 i/s - 1.10x (± 0.00) slower
block + yield: 9886042.1 i/s - 1.31x (± 0.00) slower
block.call: 9463241.0 i/s - 1.37x (± 0.00) slower
$ ruby -v code/range/cover-vs-include.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
range#cover? 323.129k i/100ms
range#include? 12.754k i/100ms
range#member? 12.609k i/100ms
plain compare 533.623k i/100ms
Calculating -------------------------------------
range#cover? 3.258M (± 1.1%) i/s - 16.480M in 5.059325s
range#include? 129.686k (± 0.5%) i/s - 650.454k in 5.015723s
range#member? 128.371k (± 0.4%) i/s - 643.059k in 5.009479s
plain compare 5.320M (± 0.3%) i/s - 26.681M in 5.015255s
Comparison:
plain compare: 5320033.3 i/s
range#cover?: 3257677.8 i/s - 1.63x (± 0.00) slower
range#include?: 129686.0 i/s - 41.02x (± 0.00) slower
range#member?: 128371.1 i/s - 41.44x (± 0.00) slower
$ ruby -v code/string/===-vs-=~-vs-match.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#match? 886.942k i/100ms
String#=~ 654.463k i/100ms
Regexp#=== 577.288k i/100ms
String#match 468.920k i/100ms
Calculating -------------------------------------
String#match? 9.122M (± 0.7%) i/s - 46.121M in 5.056187s
String#=~ 6.505M (± 0.7%) i/s - 32.723M in 5.030600s
Regexp#=== 5.717M (± 0.5%) i/s - 28.864M in 5.049386s
String#match 4.690M (± 0.5%) i/s - 23.915M in 5.098943s
Comparison:
String#match?: 9122159.1 i/s
String#=~: 6505112.1 i/s - 1.40x (± 0.00) slower
Regexp#===: 5716545.3 i/s - 1.60x (± 0.00) slower
String#match: 4690283.6 i/s - 1.94x (± 0.00) slower
$ ruby -v code/string/casecmp-vs-downcase-==.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#downcase + == 646.047k i/100ms
String#casecmp 803.982k i/100ms
Calculating -------------------------------------
String#downcase + == 6.483M (± 0.2%) i/s - 32.948M in 5.082661s
String#casecmp 8.019M (± 0.5%) i/s - 40.199M in 5.013172s
Comparison:
String#casecmp: 8018886.5 i/s
String#downcase + ==: 6482525.8 i/s - 1.24x (± 0.00) slower
$ ruby -v code/string/concatenation.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#+ 601.610k i/100ms
String#concat 627.408k i/100ms
String#append 677.195k i/100ms
"foo" "bar" 1.188M i/100ms
"#{'foo'}#{'bar'}" 1.187M i/100ms
Calculating -------------------------------------
String#+ 6.053M (± 0.3%) i/s - 30.682M in 5.069175s
String#concat 6.250M (± 0.2%) i/s - 31.370M in 5.019126s
String#append 6.746M (± 0.2%) i/s - 33.860M in 5.019359s
"foo" "bar" 11.845M (± 0.3%) i/s - 59.425M in 5.016779s
"#{'foo'}#{'bar'}" 11.870M (± 0.3%) i/s - 59.367M in 5.001317s
Comparison:
"#{'foo'}#{'bar'}": 11870351.0 i/s
"foo" "bar": 11845265.3 i/s - same-ish: difference falls within error
String#append: 6745867.2 i/s - 1.76x (± 0.00) slower
String#concat: 6250206.0 i/s - 1.90x (± 0.00) slower
String#+: 6052740.0 i/s - 1.96x (± 0.00) slower
$ ruby -v code/string/dup-vs-unary-plus.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#+@ 1.001M i/100ms
String#dup 577.228k i/100ms
Calculating -------------------------------------
String#+@ 10.006M (± 0.4%) i/s - 51.040M in 5.101053s
String#dup 5.797M (± 0.8%) i/s - 29.439M in 5.078574s
Comparison:
String#+@: 10005895.7 i/s
String#dup: 5796994.9 i/s - 1.73x (± 0.00) slower
$ ruby -v code/string/end-string-checking-match-vs-end_with.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#=~ 189.234k i/100ms
String#match? 427.115k i/100ms
String#end_with? 624.922k i/100ms
Calculating -------------------------------------
String#=~ 1.892M (± 0.4%) i/s - 9.462M in 4.999974s
String#match? 4.272M (± 0.8%) i/s - 21.783M in 5.099518s
String#end_with? 6.209M (± 0.4%) i/s - 31.246M in 5.032494s
Comparison:
String#end_with?: 6208979.4 i/s
String#match?: 4271865.7 i/s - 1.45x (± 0.00) slower
String#=~: 1892377.7 i/s - 3.28x (± 0.00) slower
$ ruby -v code/string/gsub-vs-sub.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#gsub 112.555k i/100ms
String#sub 139.170k i/100ms
String#dup["string"]=
181.415k i/100ms
Calculating -------------------------------------
String#gsub 1.133M (± 4.0%) i/s - 5.740M in 5.076268s
String#sub 1.369M (± 0.5%) i/s - 6.958M in 5.083300s
String#dup["string"]=
1.806M (± 0.6%) i/s - 9.071M in 5.021399s
Comparison:
String#dup["string"]=: 1806474.1 i/s
String#sub: 1368930.8 i/s - 1.32x (± 0.00) slower
String#gsub: 1133059.1 i/s - 1.59x (± 0.00) slower
$ ruby -v code/string/gsub-vs-tr.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#gsub 105.984k i/100ms
String#tr 338.562k i/100ms
Calculating -------------------------------------
String#gsub 1.055M (± 0.8%) i/s - 5.299M in 5.022698s
String#tr 3.384M (± 0.4%) i/s - 16.928M in 5.003157s
Comparison:
String#tr: 3383540.6 i/s
String#gsub: 1055120.9 i/s - 3.21x (± 0.00) slower
$ ruby -v code/string/mutable_vs_immutable_strings.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Without Freeze 1.170M i/100ms
With Freeze 1.672M i/100ms
Calculating -------------------------------------
Without Freeze 11.743M (± 0.7%) i/s - 59.671M in 5.081841s
With Freeze 16.871M (± 0.3%) i/s - 85.261M in 5.053663s
Comparison:
With Freeze: 16871328.1 i/s
Without Freeze: 11742589.8 i/s - 1.44x (± 0.00) slower
$ ruby -v code/string/remove-extra-spaces-or-other-chars.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#gsub/regex+/ 3.467k i/100ms
String#squeeze 156.347k i/100ms
Calculating -------------------------------------
String#gsub/regex+/ 34.552k (± 0.5%) i/s - 173.350k in 5.017267s
String#squeeze 1.573M (± 0.6%) i/s - 7.974M in 5.068803s
Comparison:
String#squeeze: 1573143.9 i/s
String#gsub/regex+/: 34551.5 i/s - 45.53x (± 0.00) slower
$ ruby -v code/string/start-string-checking-match-vs-start_with.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#=~ 285.342k i/100ms
String#match? 759.625k i/100ms
String#start_with? 864.845k i/100ms
Calculating -------------------------------------
String#=~ 2.829M (± 0.7%) i/s - 14.267M in 5.043099s
String#match? 7.576M (± 1.3%) i/s - 37.981M in 5.014384s
String#start_with? 8.593M (± 0.2%) i/s - 43.242M in 5.032359s
Comparison:
String#start_with?: 8592864.5 i/s
String#match?: 7575807.2 i/s - 1.13x (± 0.00) slower
String#=~: 2829172.7 i/s - 3.04x (± 0.00) slower
$ ruby -v code/string/start_with-vs-substring-==.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#start_with? 189.779k i/100ms
String#[0, n] == 80.544k i/100ms
String#[RANGE] == 75.178k i/100ms
String#[0...n] == 47.894k i/100ms
Calculating -------------------------------------
String#start_with? 1.889M (± 1.5%) i/s - 9.489M in 5.023384s
String#[0, n] == 807.541k (± 0.6%) i/s - 4.108M in 5.086913s
String#[RANGE] == 755.042k (± 1.0%) i/s - 3.834M in 5.078517s
String#[0...n] == 470.935k (± 0.9%) i/s - 2.395M in 5.085368s
Comparison:
String#start_with?: 1889406.9 i/s
String#[0, n] ==: 807541.0 i/s - 2.34x (± 0.00) slower
String#[RANGE] ==: 755042.5 i/s - 2.50x (± 0.00) slower
String#[0...n] ==: 470934.6 i/s - 4.01x (± 0.00) slower
$ ruby -v code/string/sub!-vs-gsub!-vs-[]=.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#['string']= 186.363k i/100ms
String#sub!'string' 127.819k i/100ms
String#gsub!'string' 78.160k i/100ms
String#[/regexp/]= 151.944k i/100ms
String#sub!/regexp/ 114.257k i/100ms
String#gsub!/regexp/ 61.577k i/100ms
Calculating -------------------------------------
String#['string']= 1.813M (± 0.6%) i/s - 9.132M in 5.036059s
String#sub!'string' 1.279M (± 0.6%) i/s - 6.519M in 5.096296s
String#gsub!'string' 783.065k (± 0.3%) i/s - 3.986M in 5.090495s
String#[/regexp/]= 1.540M (± 0.6%) i/s - 7.749M in 5.030672s
String#sub!/regexp/ 1.148M (± 0.5%) i/s - 5.827M in 5.074513s
String#gsub!/regexp/ 605.809k (± 0.5%) i/s - 3.079M in 5.082323s
Comparison:
String#['string']=: 1813335.2 i/s
String#[/regexp/]=: 1540440.0 i/s - 1.18x (± 0.00) slower
String#sub!'string': 1279161.2 i/s - 1.42x (± 0.00) slower
String#sub!/regexp/: 1148333.1 i/s - 1.58x (± 0.00) slower
String#gsub!'string': 783065.5 i/s - 2.32x (± 0.00) slower
String#gsub!/regexp/: 605808.8 i/s - 2.99x (± 0.00) slower
$ ruby -v code/string/sub-vs-chomp-vs-delete_suffix.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#sub 142.324k i/100ms
String#chomp 554.915k i/100ms
String#delete_suffix 611.758k i/100ms
Calculating -------------------------------------
String#sub 1.435M (± 0.2%) i/s - 7.259M in 5.057212s
String#chomp 5.548M (± 0.7%) i/s - 27.746M in 5.001218s
String#delete_suffix 6.080M (± 0.6%) i/s - 30.588M in 5.031009s
Comparison:
String#delete_suffix: 6080099.5 i/s
String#chomp: 5548103.2 i/s - 1.10x (± 0.00) slower
String#sub: 1435287.0 i/s - 4.24x (± 0.00) slower
$ ruby -v code/string/sub-vs-delete_prefix.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#delete_prefix 625.731k i/100ms
String#sub 146.536k i/100ms
Calculating -------------------------------------
String#delete_prefix 6.208M (± 0.6%) i/s - 31.287M in 5.039895s
String#sub 1.468M (± 0.5%) i/s - 7.473M in 5.089261s
Comparison:
String#delete_prefix: 6207969.4 i/s
String#sub: 1468493.1 i/s - 4.23x (± 0.00) slower
$ ruby -v code/string/unpack1-vs-unpack[0].rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
String#unpack1 622.034k i/100ms
String#unpack[0] 468.540k i/100ms
Calculating -------------------------------------
String#unpack1 6.222M (± 0.6%) i/s - 31.724M in 5.098677s
String#unpack[0] 4.761M (± 0.4%) i/s - 23.896M in 5.018861s
Comparison:
String#unpack1: 6222224.7 i/s
String#unpack[0]: 4761234.8 i/s - 1.31x (± 0.00) slower
$ ruby -v code/time/iso8601-vs-parse.rb
ruby 3.1.5p252 (2024-04-23 revision 1945f8dc0e) [x86_64-linux]
Warming up --------------------------------------
Time.iso8601 26.952k i/100ms
Time.parse 9.374k i/100ms
Calculating -------------------------------------
Time.iso8601 270.860k (± 1.9%) i/s - 1.375M in 5.076863s
Time.parse 94.080k (± 0.5%) i/s - 478.074k in 5.081668s
Comparison:
Time.iso8601: 270860.5 i/s
Time.parse: 94080.2 i/s - 2.88x (± 0.00) slower