forked from fastruby/fast-ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
truffleruby-3.1.3.fastruby
922 lines (800 loc) · 42 KB
/
truffleruby-3.1.3.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
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Function with single Array argument
238.342M i/100ms
Function with splat arguments
784.000 i/100ms
Calculating -------------------------------------
Function with single Array argument
2.387B (± 0.3%) i/s - 12.155B in 5.092727s
Function with splat arguments
8.081k (± 7.5%) i/s - 40.768k in 5.090090s
Comparison:
Function with single Array argument: 2386838210.3 i/s
Function with splat arguments: 8080.7 i/s - 295376.27x (± 0.00) slower
$ ruby -v code/general/assignment.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Parallel Assignment 238.533M i/100ms
Sequential Assignment
238.744M i/100ms
Calculating -------------------------------------
Parallel Assignment 2.381B (± 0.9%) i/s - 11.927B in 5.008635s
Sequential Assignment
2.388B (± 0.2%) i/s - 12.176B in 5.099160s
Comparison:
Sequential Assignment: 2387850768.1 i/s
Parallel Assignment: 2381410047.5 i/s - same-ish: difference falls within error
$ ruby -v code/general/attr-accessor-vs-getter-and-setter.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
getter_and_setter 238.451M i/100ms
attr_accessor 238.252M i/100ms
Calculating -------------------------------------
getter_and_setter 2.385B (± 0.4%) i/s - 12.161B in 5.098454s
attr_accessor 2.385B (± 0.4%) i/s - 12.151B in 5.093859s
Comparison:
attr_accessor: 2385427532.4 i/s
getter_and_setter: 2385264574.1 i/s - same-ish: difference falls within error
$ ruby -v code/general/begin-rescue-vs-respond-to.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
begin...rescue 7.878k i/100ms
respond_to? 238.074M i/100ms
Calculating -------------------------------------
begin...rescue 51.545k (± 2.2%) i/s - 259.974k in 5.046108s
respond_to? 2.388B (± 0.2%) i/s - 12.142B in 5.084724s
Comparison:
respond_to?: 2387906302.3 i/s
begin...rescue: 51544.9 i/s - 46326.76x (± 0.00) slower
$ ruby -v code/general/block-apply-method.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
normal 238.330M i/100ms
&method 238.515M i/100ms
Calculating -------------------------------------
normal 2.385B (± 0.3%) i/s - 12.155B in 5.097441s
&method 2.387B (± 0.3%) i/s - 12.164B in 5.096051s
Comparison:
&method: 2387022989.8 i/s
normal: 2384513826.7 i/s - same-ish: difference falls within error
$ ruby -v code/general/define_method-vs-module-eval.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
module_eval with string
100.000 i/100ms
define_method 129.000 i/100ms
Calculating -------------------------------------
module_eval with string
1.624k (±57.2%) i/s - 4.000k in 5.790288s
define_method 4.145k (±51.4%) i/s - 7.353k in 5.011645s
Comparison:
define_method: 4144.5 i/s
module_eval with string: 1623.9 i/s - same-ish: difference falls within error
$ ruby -v code/general/format-vs-round-and-to-s.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Float#round 76.707k i/100ms
Kernel#format 62.763k i/100ms
String#% 63.602k i/100ms
Calculating -------------------------------------
Float#round 757.637k (± 2.5%) i/s - 3.835M in 5.065620s
Kernel#format 630.618k (± 2.3%) i/s - 3.201M in 5.078746s
String#% 631.638k (± 2.6%) i/s - 3.180M in 5.038345s
Comparison:
Float#round: 757636.9 i/s
String#%: 631637.6 i/s - 1.20x (± 0.00) slower
Kernel#format: 630618.0 i/s - 1.20x (± 0.00) slower
$ ruby -v code/general/hash-vs-openstruct-on-access.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash 238.191M i/100ms
OpenStruct 238.363M i/100ms
Calculating -------------------------------------
Hash 2.387B (± 0.4%) i/s - 12.148B in 5.089699s
OpenStruct 2.387B (± 0.4%) i/s - 12.157B in 5.092513s
Comparison:
OpenStruct: 2387169672.2 i/s
Hash: 2386764434.0 i/s - same-ish: difference falls within error
$ ruby -v code/general/hash-vs-openstruct.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash 238.364M i/100ms
OpenStruct 2.754k i/100ms
Calculating -------------------------------------
Hash 2.381B (± 0.4%) i/s - 11.918B in 5.004839s
OpenStruct 28.829k (±11.3%) i/s - 145.962k in 5.162940s
Comparison:
Hash: 2381378480.4 i/s
OpenStruct: 28829.4 i/s - 82602.57x (± 0.00) slower
$ ruby -v code/general/inheritance-check.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
less than or equal 731.482k i/100ms
ancestors.include? 143.038k i/100ms
Calculating -------------------------------------
less than or equal 7.757M (± 2.4%) i/s - 38.769M in 5.000718s
ancestors.include? 1.356M (± 7.3%) i/s - 6.723M in 5.000151s
Comparison:
less than or equal: 7757229.3 i/s
ancestors.include?: 1355875.4 i/s - 5.72x (± 0.00) slower
$ ruby -v code/general/loop-vs-while-true.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
While Loop 1.000 i/100ms
Kernel loop 1.000 i/100ms
Calculating -------------------------------------
While Loop 23.866 (± 0.0%) i/s - 120.000 in 5.028103s
Kernel loop 23.883 (± 0.0%) i/s - 120.000 in 5.024646s
Comparison:
Kernel loop: 23.9 i/s
While Loop: 23.9 i/s - 1.00x (± 0.00) slower
$ ruby -v code/general/raise-vs-e2mmap.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
$ ruby -v code/array/array-first-vs-index.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Array#[0] 238.312M i/100ms
Array#first 238.437M i/100ms
Calculating -------------------------------------
Array#[0] 2.385B (± 0.4%) i/s - 12.154B in 5.095610s
Array#first 2.387B (± 0.3%) i/s - 12.160B in 5.093770s
Comparison:
Array#first: 2387304046.5 i/s
Array#[0]: 2385203359.5 i/s - same-ish: difference falls within error
$ ruby -v code/array/array-last-vs-index.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Array#[-1] 238.446M i/100ms
Array#last 238.401M i/100ms
Calculating -------------------------------------
Array#[-1] 2.386B (± 0.3%) i/s - 12.161B in 5.096762s
Array#last 2.388B (± 0.3%) i/s - 12.158B in 5.091829s
Comparison:
Array#last: 2387854296.2 i/s
Array#[-1]: 2386003108.6 i/s - same-ish: difference falls within error
$ ruby -v code/array/bsearch-vs-find.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
find 1.000 i/100ms
bsearch 490.745k i/100ms
Calculating -------------------------------------
find 7.148 (±28.0%) i/s - 16.000 in 5.050196s
bsearch 4.977M (± 3.5%) i/s - 25.028M in 5.035539s
Comparison:
bsearch: 4976688.6 i/s
find: 7.1 i/s - 696226.14x (± 0.00) slower
$ ruby -v code/array/insert-vs-unshift.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Array#unshift 1.000 i/100ms
Array#insert 1.000 i/100ms
Calculating -------------------------------------
Array#unshift 0.124 (± 0.0%) i/s - 1.000 in 8.052963s
Array#insert 0.945 (± 0.0%) i/s - 5.000 in 5.292156s
Comparison:
Array#insert: 0.9 i/s
Array#unshift: 0.1 i/s - 7.61x (± 0.00) slower
$ ruby -v code/array/length-vs-size-vs-count.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Array#length 238.140M i/100ms
Array#size 236.019M i/100ms
Array#count 239.081M i/100ms
Calculating -------------------------------------
Array#length 2.387B (± 0.3%) i/s - 12.145B in 5.088795s
Array#size 2.389B (± 0.2%) i/s - 12.037B in 5.038259s
Array#count 2.389B (± 0.2%) i/s - 11.954B in 5.004656s
Comparison:
Array#size: 2389128986.6 i/s
Array#count: 2388596866.6 i/s - same-ish: difference falls within error
Array#length: 2386673156.5 i/s - same-ish: difference falls within error
$ ruby -v code/array/shuffle-first-vs-sample.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Array#shuffle.first 22.896k i/100ms
Array#sample 2.498M i/100ms
Calculating -------------------------------------
Array#shuffle.first 237.662k (± 2.3%) i/s - 1.191M in 5.012449s
Array#sample 24.926M (± 0.3%) i/s - 124.893M in 5.010640s
Comparison:
Array#sample: 24925722.3 i/s
Array#shuffle.first: 237662.3 i/s - 104.88x (± 0.00) slower
$ ruby -v code/date/iso8601-vs-parse.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Date.iso8601 967.000 i/100ms
Date.parse 705.000 i/100ms
Calculating -------------------------------------
Date.iso8601 30.908k (±28.3%) i/s - 132.479k in 5.014745s
Date.parse 16.613k (±32.9%) i/s - 69.090k in 5.011535s
Comparison:
Date.iso8601: 30907.9 i/s
Date.parse: 16612.8 i/s - 1.86x (± 0.00) slower
$ ruby -v code/enumerable/each-push-vs-map.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Array#each + push 138.210k i/100ms
Array#map 599.949k i/100ms
Calculating -------------------------------------
Array#each + push 1.496M (± 3.1%) i/s - 7.602M in 5.085069s
Array#map 5.626M (± 8.8%) i/s - 28.198M in 5.065325s
Comparison:
Array#map: 5626173.8 i/s
Array#each + push: 1496398.4 i/s - 3.76x (± 0.00) slower
$ ruby -v code/enumerable/each-vs-for-loop.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
For loop 7.973M i/100ms
#each 24.904M i/100ms
Calculating -------------------------------------
For loop 80.653M (± 0.3%) i/s - 406.638M in 5.041903s
#each 248.690M (± 0.8%) i/s - 1.245B in 5.007372s
Comparison:
#each: 248689652.6 i/s
For loop: 80652633.7 i/s - 3.08x (± 0.00) slower
$ ruby -v code/enumerable/each_with_index-vs-while-loop.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
While Loop 961.585k i/100ms
each_with_index 1.204M i/100ms
Calculating -------------------------------------
While Loop 9.679M (± 0.2%) i/s - 49.041M in 5.066628s
each_with_index 12.066M (± 0.4%) i/s - 61.396M in 5.088398s
Comparison:
each_with_index: 12066110.0 i/s
While Loop: 9679216.4 i/s - 1.25x (± 0.00) slower
$ ruby -v code/enumerable/inject-symbol-vs-block.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
inject symbol 146.213k i/100ms
inject to_proc 147.407k i/100ms
inject block 147.352k i/100ms
Calculating -------------------------------------
inject symbol 1.473M (± 0.2%) i/s - 7.457M in 5.062444s
inject to_proc 1.474M (± 0.1%) i/s - 7.370M in 5.001525s
inject block 1.473M (± 0.2%) i/s - 7.368M in 5.000773s
Comparison:
inject to_proc: 1473623.5 i/s
inject block: 1473295.7 i/s - same-ish: difference falls within error
inject symbol: 1472985.0 i/s - same-ish: difference falls within error
$ ruby -v code/enumerable/map-flatten-vs-flat_map.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Array#map.flatten(1) 11.631k i/100ms
Array#map.flatten 11.471k i/100ms
Array#flat_map 32.360k i/100ms
Calculating -------------------------------------
Array#map.flatten(1) 123.633k (± 3.6%) i/s - 628.074k in 5.087055s
Array#map.flatten 122.606k (± 4.3%) i/s - 619.434k in 5.061654s
Array#flat_map 327.946k (± 2.6%) i/s - 1.650M in 5.036076s
Comparison:
Array#flat_map: 327946.5 i/s
Array#map.flatten(1): 123632.6 i/s - 2.65x (± 0.00) slower
Array#map.flatten: 122606.1 i/s - 2.67x (± 0.00) slower
$ ruby -v code/enumerable/reverse-each-vs-reverse_each.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Array#reverse.each 172.063k i/100ms
Array#reverse_each 1.878M i/100ms
Calculating -------------------------------------
Array#reverse.each 1.912M (± 6.9%) i/s - 9.636M in 5.081473s
Array#reverse_each 18.808M (± 0.3%) i/s - 95.795M in 5.093294s
Comparison:
Array#reverse_each: 18808132.9 i/s
Array#reverse.each: 1911600.4 i/s - 9.84x (± 0.00) slower
$ ruby -v code/enumerable/select-first-vs-detect.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Enumerable#select.first
568.410k i/100ms
Enumerable#detect 3.471M i/100ms
Calculating -------------------------------------
Enumerable#select.first
6.268M (± 7.6%) i/s - 124.482M in 20.036939s
Enumerable#detect 34.729M (± 0.2%) i/s - 697.612M in 20.087524s
Comparison:
Enumerable#detect: 34728733.7 i/s
Enumerable#select.first: 6268172.3 i/s - 5.54x (± 0.00) slower
$ ruby -v code/enumerable/select-last-vs-reverse-detect.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Enumerable#reverse.detect
187.729k i/100ms
Enumerable#select.last
384.608k i/100ms
Calculating -------------------------------------
Enumerable#reverse.detect
1.867M (± 3.5%) i/s - 9.386M in 5.034186s
Enumerable#select.last
3.846M (± 2.1%) i/s - 19.230M in 5.002178s
Comparison:
Enumerable#select.last: 3846123.8 i/s
Enumerable#reverse.detect: 1866849.9 i/s - 2.06x (± 0.00) slower
$ ruby -v code/enumerable/sort-vs-sort_by.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Enumerable#sort_by (Symbol#to_proc)
2.304k i/100ms
Enumerable#sort_by 2.449k i/100ms
Enumerable#sort 3.142k i/100ms
Calculating -------------------------------------
Enumerable#sort_by (Symbol#to_proc)
23.811k (±20.6%) i/s - 108.288k in 5.079552s
Enumerable#sort_by 24.293k (±18.0%) i/s - 112.654k in 5.004031s
Enumerable#sort 33.328k (± 3.3%) i/s - 166.526k in 5.002649s
Comparison:
Enumerable#sort: 33328.0 i/s
Enumerable#sort_by: 24293.3 i/s - 1.37x (± 0.00) slower
Enumerable#sort_by (Symbol#to_proc): 23810.9 i/s - 1.40x (± 0.00) slower
$ ruby -v code/enumerable/sort_by-first-vs-min_by.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Enumerable#min_by 512.405k i/100ms
Enumerable#sort_by...first
5.066k i/100ms
Calculating -------------------------------------
Enumerable#min_by 5.159M (± 0.3%) i/s - 26.133M in 5.065460s
Enumerable#sort_by...first
58.985k (± 2.9%) i/s - 298.894k in 5.071677s
Comparison:
Enumerable#min_by: 5159038.9 i/s
Enumerable#sort_by...first: 58985.1 i/s - 87.46x (± 0.00) slower
$ ruby -v code/hash/bracket-vs-dup.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash[] 172.604k i/100ms
Hash#dup 222.338k i/100ms
Calculating -------------------------------------
Hash[] 2.179M (± 4.5%) i/s - 10.874M in 5.001097s
Hash#dup 2.225M (± 2.9%) i/s - 11.117M in 5.000643s
Comparison:
Hash#dup: 2225025.2 i/s
Hash[]: 2178728.7 i/s - same-ish: difference falls within error
$ ruby -v code/hash/bracket-vs-fetch.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#[], symbol 238.557M i/100ms
Hash#fetch, symbol 238.493M i/100ms
Hash#[], string 2.375M i/100ms
Hash#fetch, string 2.480M i/100ms
Calculating -------------------------------------
Hash#[], symbol 2.387B (± 0.3%) i/s - 12.166B in 5.096946s
Hash#fetch, symbol 2.387B (± 0.4%) i/s - 12.163B in 5.095476s
Hash#[], string 157.116M (± 0.5%) i/s - 786.104M in 5.003462s
Hash#fetch, string 143.010M (± 1.9%) i/s - 716.819M in 5.014264s
Comparison:
Hash#fetch, symbol: 2387082687.9 i/s
Hash#[], symbol: 2387021511.1 i/s - same-ish: difference falls within error
Hash#[], string: 157115747.0 i/s - 15.19x (± 0.00) slower
Hash#fetch, string: 143009833.0 i/s - 16.69x (± 0.00) slower
$ ruby -v code/hash/dig-vs-[]-vs-fetch.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#dig 49.699M i/100ms
Hash#[] 49.735M i/100ms
Hash#[] || 49.806M i/100ms
Hash#[] && 49.792M i/100ms
Hash#fetch 49.798M i/100ms
Hash#fetch fallback 49.785M i/100ms
Calculating -------------------------------------
Hash#dig 497.423M (± 0.3%) i/s - 2.535B in 5.095632s
Hash#[] 497.812M (± 0.2%) i/s - 2.536B in 5.095244s
Hash#[] || 497.723M (± 0.2%) i/s - 2.490B in 5.003446s
Hash#[] && 497.747M (± 0.2%) i/s - 2.490B in 5.001733s
Hash#fetch 497.900M (± 0.1%) i/s - 2.490B in 5.000838s
Hash#fetch fallback 497.800M (± 0.2%) i/s - 2.489B in 5.000478s
Comparison:
Hash#fetch: 497899664.5 i/s
Hash#[]: 497812052.5 i/s - same-ish: difference falls within error
Hash#fetch fallback: 497800152.4 i/s - same-ish: difference falls within error
Hash#[] &&: 497746582.6 i/s - same-ish: difference falls within error
Hash#[] ||: 497722577.6 i/s - same-ish: difference falls within error
Hash#dig: 497422636.0 i/s - same-ish: difference falls within error
$ ruby -v code/hash/fetch-vs-fetch-with-block.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#fetch + const 238.762M i/100ms
Hash#fetch + block 238.407M i/100ms
Hash#fetch + arg 238.740M i/100ms
Calculating -------------------------------------
Hash#fetch + const 2.385B (± 0.4%) i/s - 11.938B in 5.005791s
Hash#fetch + block 2.388B (± 0.3%) i/s - 12.159B in 5.091358s
Hash#fetch + arg 2.381B (± 1.2%) i/s - 11.937B in 5.013863s
Comparison:
Hash#fetch + block: 2388135683.4 i/s
Hash#fetch + const: 2384900781.0 i/s - same-ish: difference falls within error
Hash#fetch + arg: 2381138971.5 i/s - same-ish: difference falls within error
$ ruby -v code/hash/hash-key-sort_by-vs-sort.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
sort_by + to_h 17.737k i/100ms
sort + to_h 7.847k i/100ms
Calculating -------------------------------------
sort_by + to_h 283.073k (± 7.9%) i/s - 1.401M in 5.008796s
sort + to_h 107.970k (± 8.9%) i/s - 533.596k in 5.007115s
Comparison:
sort_by + to_h: 283072.6 i/s
sort + to_h: 107970.3 i/s - 2.62x (± 0.00) slower
$ ruby -v code/hash/keys-each-vs-each_key.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#keys.each 116.897k i/100ms
Hash#each_key 132.820k i/100ms
Calculating -------------------------------------
Hash#keys.each 1.217M (±11.9%) i/s - 5.962M in 5.041182s
Hash#each_key 1.340M (± 3.7%) i/s - 6.774M in 5.062753s
Comparison:
Hash#each_key: 1339775.4 i/s
Hash#keys.each: 1217186.9 i/s - same-ish: difference falls within error
$ ruby -v code/hash/keys-include-vs-key.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#keys.include? 159.000 i/100ms
Hash#key? 7.289M i/100ms
Calculating -------------------------------------
Hash#keys.include? 1.743k (±10.7%) i/s - 8.586k in 5.020669s
Hash#key? 72.855M (± 0.2%) i/s - 364.433M in 5.002191s
Comparison:
Hash#key?: 72854860.7 i/s
Hash#keys.include?: 1743.0 i/s - 41798.44x (± 0.00) slower
$ ruby -v code/hash/merge-bang-vs-[]=.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#merge! 21.224k i/100ms
Hash#[]= 22.106k i/100ms
Calculating -------------------------------------
Hash#merge! 233.560k (± 3.8%) i/s - 1.167M in 5.005050s
Hash#[]= 229.412k (± 7.2%) i/s - 1.150M in 5.052342s
Comparison:
Hash#merge!: 233559.8 i/s
Hash#[]=: 229412.3 i/s - same-ish: difference falls within error
$ ruby -v code/hash/merge-bang-vs-merge-vs-dup-merge-bang.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
{}#merge!(Hash) do end
11.443k i/100ms
Hash#merge({}) 8.322k i/100ms
Hash#dup#merge!({}) 14.328k i/100ms
Calculating -------------------------------------
{}#merge!(Hash) do end
133.243k (± 4.4%) i/s - 675.137k in 5.077338s
Hash#merge({}) 82.118k (± 7.4%) i/s - 407.778k in 5.010042s
Hash#dup#merge!({}) 139.215k (± 8.0%) i/s - 702.072k in 5.092293s
Comparison:
Hash#dup#merge!({}): 139215.5 i/s
{}#merge!(Hash) do end: 133242.8 i/s - same-ish: difference falls within error
Hash#merge({}): 82117.8 i/s - 1.70x (± 0.00) slower
$ ruby -v code/hash/merge-vs-double-splat-operator.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#**other 238.356M i/100ms
Hash#merge 239.145M i/100ms
Calculating -------------------------------------
Hash#**other 2.387B (± 0.3%) i/s - 12.156B in 5.092774s
Hash#merge 2.383B (± 1.2%) i/s - 11.957B in 5.017775s
Comparison:
Hash#**other: 2386964605.1 i/s
Hash#merge: 2383335377.3 i/s - same-ish: difference falls within error
$ ruby -v code/hash/merge-vs-merge-bang.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#merge 288.000 i/100ms
Hash#merge! 23.035k i/100ms
Calculating -------------------------------------
Hash#merge 3.292k (± 7.6%) i/s - 16.416k in 5.034006s
Hash#merge! 235.050k (± 5.6%) i/s - 1.175M in 5.013880s
Comparison:
Hash#merge!: 235050.0 i/s
Hash#merge: 3291.8 i/s - 71.40x (± 0.00) slower
$ ruby -v code/hash/slice-native-vs-before-native.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#native-slice 1.062M i/100ms
Array#each 993.999k i/100ms
Array#each_w/_object 1.004M i/100ms
Hash#select-include 1.306M i/100ms
Calculating -------------------------------------
Hash#native-slice 11.390M (± 3.6%) i/s - 57.353M in 5.042264s
Array#each 10.123M (± 2.9%) i/s - 50.694M in 5.012341s
Array#each_w/_object 10.033M (± 3.6%) i/s - 50.204M in 5.010349s
Hash#select-include 12.987M (± 3.4%) i/s - 65.320M in 5.035488s
Comparison:
Hash#select-include : 12987252.0 i/s
Hash#native-slice : 11389509.7 i/s - 1.14x (± 0.00) slower
Array#each : 10122800.0 i/s - 1.28x (± 0.00) slower
Array#each_w/_object: 10033197.1 i/s - 1.29x (± 0.00) slower
$ ruby -v code/hash/values-include-vs-value.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Hash#values.include? 186.000 i/100ms
Hash#value? 3.421k i/100ms
Calculating -------------------------------------
Hash#values.include? 2.292k (±10.4%) i/s - 11.346k in 5.033035s
Hash#value? 33.818k (± 0.3%) i/s - 171.050k in 5.057956s
Comparison:
Hash#value?: 33818.2 i/s
Hash#values.include?: 2292.4 i/s - 14.75x (± 0.00) slower
$ ruby -v code/method/call-vs-send-vs-method_missing.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
call 238.416M i/100ms
send 238.702M i/100ms
method_missing 239.071M i/100ms
Calculating -------------------------------------
call 2.387B (± 0.3%) i/s - 12.159B in 5.094854s
send 2.388B (± 0.3%) i/s - 12.174B in 5.097274s
method_missing 2.389B (± 0.2%) i/s - 11.954B in 5.003010s
Comparison:
method_missing: 2389277826.6 i/s
send: 2388311846.1 i/s - same-ish: difference falls within error
call: 2386593835.6 i/s - same-ish: difference falls within error
$ ruby -v code/proc-and-block/block-vs-to_proc.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Block 14.632k i/100ms
Symbol#to_proc 16.001k i/100ms
Calculating -------------------------------------
Block 162.377k (± 3.7%) i/s - 819.392k in 5.053159s
Symbol#to_proc 161.435k (± 6.8%) i/s - 816.051k in 5.094773s
Comparison:
Block: 162376.7 i/s
Symbol#to_proc: 161435.0 i/s - same-ish: difference falls within error
$ ruby -v code/proc-and-block/proc-call-vs-yield.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
block.call 238.346M i/100ms
block + yield 238.361M i/100ms
unused block 239.123M i/100ms
yield 239.128M i/100ms
Calculating -------------------------------------
block.call 2.388B (± 0.2%) i/s - 12.156B in 5.089731s
block + yield 2.383B (± 1.1%) i/s - 11.918B in 5.001181s
unused block 2.389B (± 0.2%) i/s - 11.956B in 5.004197s
yield 2.388B (± 0.3%) i/s - 11.956B in 5.006489s
Comparison:
unused block: 2389234091.6 i/s
block.call: 2388282610.9 i/s - same-ish: difference falls within error
yield: 2388201361.3 i/s - same-ish: difference falls within error
block + yield: 2383367881.6 i/s - same-ish: difference falls within error
$ ruby -v code/range/cover-vs-include.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
range#cover? 17.042k i/100ms
range#include? 365.000 i/100ms
range#member? 751.000 i/100ms
plain compare 29.083k i/100ms
Calculating -------------------------------------
range#cover? 171.343k (±24.1%) i/s - 800.974k in 5.049390s
range#include? 9.055k (±32.2%) i/s - 39.420k in 5.026707s
range#member? 8.533k (±33.0%) i/s - 38.301k in 5.098314s
plain compare 310.928k (± 5.8%) i/s - 1.570M in 5.071569s
Comparison:
plain compare: 310928.1 i/s
range#cover?: 171342.6 i/s - 1.81x (± 0.00) slower
range#include?: 9055.4 i/s - 34.34x (± 0.00) slower
range#member?: 8532.8 i/s - 36.44x (± 0.00) slower
$ ruby -v code/string/===-vs-=~-vs-match.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#match? 9.624M i/100ms
String#=~ 9.643M i/100ms
Regexp#=== 9.644M i/100ms
String#match 8.515M i/100ms
Calculating -------------------------------------
String#match? 92.815M (± 0.3%) i/s - 471.577M in 5.080859s
String#=~ 96.405M (± 0.2%) i/s - 482.164M in 5.001470s
Regexp#=== 96.393M (± 0.2%) i/s - 482.201M in 5.002467s
String#match 85.125M (± 0.1%) i/s - 425.726M in 5.001185s
Comparison:
String#=~: 96404604.1 i/s
Regexp#===: 96392956.6 i/s - same-ish: difference falls within error
String#match?: 92815207.8 i/s - 1.04x (± 0.00) slower
String#match: 85125217.5 i/s - 1.13x (± 0.00) slower
$ ruby -v code/string/casecmp-vs-downcase-==.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#downcase + == 1.591M i/100ms
String#casecmp 2.620M i/100ms
Calculating -------------------------------------
String#downcase + == 16.585M (± 7.0%) i/s - 82.708M in 5.027966s
String#casecmp 27.153M (± 4.7%) i/s - 136.221M in 5.028132s
Comparison:
String#casecmp: 27152811.1 i/s
String#downcase + ==: 16585030.7 i/s - 1.64x (± 0.00) slower
$ ruby -v code/string/concatenation.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#+ 6.493M i/100ms
String#concat 6.893M i/100ms
String#append 6.836M i/100ms
"foo" "bar" 238.979M i/100ms
"#{'foo'}#{'bar'}" 239.067M i/100ms
Calculating -------------------------------------
String#+ 67.681M (± 6.9%) i/s - 337.644M in 5.028082s
String#concat 69.303M (± 4.1%) i/s - 351.533M in 5.081138s
String#append 69.797M (± 2.5%) i/s - 355.462M in 5.096116s
"foo" "bar" 2.390B (± 0.1%) i/s - 11.949B in 4.999928s
"#{'foo'}#{'bar'}" 2.390B (± 0.1%) i/s - 11.953B in 5.002344s
Comparison:
"foo" "bar": 2389826866.6 i/s
"#{'foo'}#{'bar'}": 2389553185.7 i/s - same-ish: difference falls within error
String#append: 69796848.7 i/s - 34.24x (± 0.00) slower
String#concat: 69302930.0 i/s - 34.48x (± 0.00) slower
String#+: 67681159.2 i/s - 35.31x (± 0.00) slower
$ ruby -v code/string/dup-vs-unary-plus.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#+@ 238.372M i/100ms
String#dup 238.677M i/100ms
Calculating -------------------------------------
String#+@ 2.379B (± 1.2%) i/s - 11.919B in 5.011109s
String#dup 2.387B (± 0.3%) i/s - 12.173B in 5.099099s
Comparison:
String#dup: 2387212050.2 i/s
String#+@: 2378783258.5 i/s - same-ish: difference falls within error
$ ruby -v code/string/end-string-checking-match-vs-end_with.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#=~ 721.749k i/100ms
String#match? 1.233M i/100ms
String#end_with? 14.208M i/100ms
Calculating -------------------------------------
String#=~ 9.166M (± 2.9%) i/s - 46.192M in 5.043875s
String#match? 12.325M (± 0.1%) i/s - 61.664M in 5.002984s
String#end_with? 142.189M (± 0.2%) i/s - 724.628M in 5.096232s
Comparison:
String#end_with?: 142189436.3 i/s
String#match?: 12325439.5 i/s - 11.54x (± 0.00) slower
String#=~: 9166125.5 i/s - 15.51x (± 0.00) slower
$ ruby -v code/string/gsub-vs-sub.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#gsub 47.950k i/100ms
String#sub 385.497k i/100ms
String#dup["string"]=
7.471M i/100ms
Calculating -------------------------------------
String#gsub 4.224M (±12.3%) i/s - 20.427M in 5.004916s
String#sub 4.923M (± 9.0%) i/s - 24.672M in 5.071941s
String#dup["string"]=
74.685M (± 0.1%) i/s - 373.539M in 5.001540s
Comparison:
String#dup["string"]=: 74684817.0 i/s
String#sub: 4923034.3 i/s - 15.17x (± 0.00) slower
String#gsub: 4223799.8 i/s - 17.68x (± 0.00) slower
$ ruby -v code/string/gsub-vs-tr.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#gsub 43.837k i/100ms
String#tr 78.899k i/100ms
Calculating -------------------------------------
String#gsub 1.774M (±10.7%) i/s - 8.680M in 5.003381s
String#tr 796.009k (± 6.8%) i/s - 4.024M in 5.093403s
Comparison:
String#gsub: 1774457.5 i/s
String#tr: 796008.9 i/s - 2.23x (± 0.00) slower
$ ruby -v code/string/mutable_vs_immutable_strings.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Without Freeze 238.339M i/100ms
With Freeze 238.577M i/100ms
Calculating -------------------------------------
Without Freeze 2.387B (± 0.3%) i/s - 12.155B in 5.092229s
With Freeze 2.389B (± 0.2%) i/s - 12.167B in 5.093291s
Comparison:
With Freeze: 2388922875.4 i/s
Without Freeze: 2387051917.5 i/s - same-ish: difference falls within error
$ ruby -v code/string/remove-extra-spaces-or-other-chars.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#gsub/regex+/ 4.635k i/100ms
String#squeeze 24.226k i/100ms
Calculating -------------------------------------
String#gsub/regex+/ 59.868k (± 7.3%) i/s - 296.640k in 5.002324s
String#squeeze 242.400k (± 2.3%) i/s - 1.211M in 4.999864s
Comparison:
String#squeeze: 242400.5 i/s
String#gsub/regex+/: 59867.9 i/s - 4.05x (± 0.00) slower
$ ruby -v code/string/start-string-checking-match-vs-start_with.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#=~ 1.004M i/100ms
String#match? 4.333M i/100ms
String#start_with? 9.615M i/100ms
Calculating -------------------------------------
String#=~ 27.220M (± 5.0%) i/s - 136.607M in 5.033223s
String#match? 43.681M (± 0.4%) i/s - 220.969M in 5.058744s
String#start_with? 96.169M (± 0.3%) i/s - 490.374M in 5.099120s
Comparison:
String#start_with?: 96169079.4 i/s
String#match?: 43681382.7 i/s - 2.20x (± 0.00) slower
String#=~: 27219909.5 i/s - 3.53x (± 0.00) slower
$ ruby -v code/string/start_with-vs-substring-==.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#start_with? 100.658k i/100ms
String#[0, n] == 213.264k i/100ms
String#[RANGE] == 281.723k i/100ms
String#[0...n] == 194.993k i/100ms
Calculating -------------------------------------
String#start_with? 4.558M (± 0.1%) i/s - 22.849M in 5.013500s
String#[0, n] == 2.279M (± 2.9%) i/s - 11.516M in 5.058736s
String#[RANGE] == 3.021M (± 3.8%) i/s - 15.213M in 5.043647s
String#[0...n] == 1.983M (± 2.6%) i/s - 9.945M in 5.017754s
Comparison:
String#start_with?: 4557572.2 i/s
String#[RANGE] ==: 3020783.5 i/s - 1.51x (± 0.00) slower
String#[0, n] ==: 2278511.2 i/s - 2.00x (± 0.00) slower
String#[0...n] ==: 1983336.0 i/s - 2.30x (± 0.00) slower
$ ruby -v code/string/sub!-vs-gsub!-vs-[]=.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#['string']= 7.463M i/100ms
String#sub!'string' 89.408k i/100ms
String#gsub!'string' 342.436k i/100ms
String#[/regexp/]= 1.483M i/100ms
String#sub!/regexp/ 478.380k i/100ms
String#gsub!/regexp/ 366.587k i/100ms
Calculating -------------------------------------
String#['string']= 74.650M (± 0.1%) i/s - 380.631M in 5.098858s
String#sub!'string' 5.130M (±21.0%) i/s - 23.604M in 5.005567s
String#gsub!'string' 4.463M (± 4.7%) i/s - 22.601M in 5.077485s
String#[/regexp/]= 14.963M (± 2.8%) i/s - 75.613M in 5.057594s
String#sub!/regexp/ 4.995M (± 3.8%) i/s - 25.354M in 5.083515s
String#gsub!/regexp/ 4.158M (± 9.1%) i/s - 20.529M in 5.002418s
Comparison:
String#['string']=: 74650331.7 i/s
String#[/regexp/]=: 14962900.2 i/s - 4.99x (± 0.00) slower
String#sub!'string': 5130258.8 i/s - 14.55x (± 0.00) slower
String#sub!/regexp/: 4994747.3 i/s - 14.95x (± 0.00) slower
String#gsub!'string': 4462512.2 i/s - 16.73x (± 0.00) slower
String#gsub!/regexp/: 4157764.9 i/s - 17.95x (± 0.00) slower
$ ruby -v code/string/sub-vs-chomp-vs-delete_suffix.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#sub 78.471k i/100ms
String#chomp 3.843M i/100ms
String#delete_suffix 4.602M i/100ms
Calculating -------------------------------------
String#sub 16.567M (± 7.7%) i/s - 81.845M in 4.998142s
String#chomp 38.513M (± 0.3%) i/s - 196.010M in 5.089490s
String#delete_suffix 44.549M (± 7.3%) i/s - 220.884M in 5.005202s
Comparison:
String#delete_suffix: 44548966.8 i/s
String#chomp: 38512995.4 i/s - 1.16x (± 0.00) slower
String#sub: 16567462.3 i/s - 2.69x (± 0.00) slower
$ ruby -v code/string/sub-vs-delete_prefix.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#delete_prefix 238.830M i/100ms
String#sub 97.849k i/100ms
Calculating -------------------------------------
String#delete_prefix 2.387B (± 0.3%) i/s - 11.942B in 5.003728s
String#sub 106.093M (± 0.8%) i/s - 530.048M in 4.996421s
Comparison:
String#delete_prefix: 2386545224.9 i/s
String#sub: 106093046.4 i/s - 22.49x (± 0.00) slower
$ ruby -v code/string/unpack1-vs-unpack[0].rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
String#unpack1 1.184M i/100ms
String#unpack[0] 1.347M i/100ms
Calculating -------------------------------------
String#unpack1 13.608M (± 3.7%) i/s - 68.689M in 5.054868s
String#unpack[0] 13.682M (± 2.0%) i/s - 68.716M in 5.024425s
Comparison:
String#unpack[0]: 13682378.2 i/s
String#unpack1: 13607924.4 i/s - same-ish: difference falls within error
$ ruby -v code/time/iso8601-vs-parse.rb
truffleruby 23.1.0-dev-65b4c2f2, like ruby 3.1.3, GraalVM CE Native [x86_64-linux]
Warming up --------------------------------------
Time.iso8601 17.859k i/100ms
Time.parse 190.000 i/100ms
Calculating -------------------------------------
Time.iso8601 309.984k (±22.5%) i/s - 1.429M in 5.023048s
Time.parse 14.221k (±26.0%) i/s - 53.960k in 5.003744s
Comparison:
Time.iso8601: 309983.6 i/s
Time.parse: 14220.9 i/s - 21.80x (± 0.00) slower