Skip to content

Instantly share code, notes, and snippets.

@eregon
Last active Nov 24, 2019
Embed
What would you like to do?
def length1(a, b, c)
a.size + b.size + c.size
end
def length2(a, b, c)
a.size + b.size + c.size
end
def length3(a, b, c)
a.size + b.size + c.size
end
def length4(a, b, c)
a.size + b.size + c.size
end
N = 10_000_000
R = 10
ARRAYS = [[1], [2], [3]]
HASHES = [{a: 1}, {b: 2}, {c: 3}]
benchmark 'length([1], [2], [3])' do
length1([1], [2], [3])
end
benchmark 'length(*ARRAYS)' do
length2(*ARRAYS)
end
benchmark 'length({a: 1}, {b: 2}, {c: 3})' do
length3({a: 1}, {b: 2}, {c: 3})
end
benchmark 'length(*HASHES)' do
length4(*HASHES)
end
$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
$ ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb
length([1], [2], [3])
5140486.847676124
5206616.5119356755
5211817.550270316
5207594.00579436
5191749.315839535
5194675.269669143
5209963.491991194
5196413.699439124
5215135.969157775
5214258.3684540335
5208503.015645484
length(*ARRAYS)
8761706.998263612
8795997.92800335
8796199.312588679
8796892.705365414
8795193.094120808
8795208.488362337
8796491.064986918
8796953.675778074
8803502.118894016
8804142.41332071
8804729.284255322
length({a: 1}, {b: 2}, {c: 3})
4109295.3683288107
4143286.865190689
4116803.606899315
4126494.0713271424
4122082.5637286254
4116101.4404356796
4125319.682762161
4120773.860599046
4125082.3332602237
4134543.4561653207
4130858.984293666
length(*HASHES)
8623620.279752778
8654142.181553502
8657839.68540421
8656778.934138607
8658141.44082667
8657836.841541758
8655619.59010206
8658141.263731685
8652228.707170863
8642875.639356343
8656855.986886652
$ ruby -v
ruby 2.7.0preview3 (2019-11-23 master b563439274) [x86_64-linux]
$ ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb
length([1], [2], [3])
5018001.6679784395
5078482.96433677
5041142.344360423
5103139.097924431
5064045.822143541
5100107.600735084
5064114.520094464
5073305.683331563
5068403.726885318
5088420.311225086
5067702.542797175
length(*ARRAYS)
7851470.910148369
7886647.016751166
7893962.974900546
7894225.896076009
7893329.115040502
7894170.834377878
7893051.538815722
7893942.305026434
7895238.342878572
7893930.859772629
7894752.6805929225
length({a: 1}, {b: 2}, {c: 3})
4379120.250596602
4416647.992995535
4406597.964860183
4413096.984352292
4408627.181831376
4401526.729974692
4417019.570715257
4404899.36429858
4414891.608269929
4410809.400182678
4399486.446482789
length(*HASHES)
7812582.422981554
7851534.83835215
7851962.41877753
7852398.130049409
7852848.392253123
7852082.775270886
7852496.4861762365
7853716.585365752
7853297.482082495
7851905.673725062
7851394.039136068
Current master, without ruby2_keywords:
$ ruby -v
truffleruby 20.0.0-dev-e4d5dfa3, like ruby 2.6.2, GraalVM CE JVM [x86_64-linux]
$ ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb
length([1], [2], [3])
28474.187315487612
99899.17109358411
434505.4505553994
222900077.48393473
250765076.5029861
252332171.32437688
252592799.53399208
252483625.83748156
252429850.12158552
252682090.90786824
252599950.0534638
252185579.33543885
252738422.0570994
253155723.89544746
length(*ARRAYS)
235274.53396968875
1206782.1408611005
19917541.994491924
22466884.23614345
23033065.80209263
23308890.99466573
24001221.853218075
23544890.322991904
24202747.02083736
23926632.53601705
24239531.458050378
24257520.06154074
24305643.740577552
length({a: 1}, {b: 2}, {c: 3})
274081.35239279945
1532197.1256503242
12046204.715183187
72934057.91426899
73094154.90822746
73050127.27269161
73120714.00812295
73087839.3822057
73073590.30753982
73097106.94744724
73091263.30361813
73078727.80591998
73139948.5745681
73072177.86639217
length(*HASHES)
436684.62124205707
1855185.7037914132
23849814.682362776
23459455.395096872
23834119.880609814
23874108.992009055
23627851.537435442
23834362.13847574
23846845.108013205
23853411.462500636
23828204.0483999
23869710.801406264
23885199.575850885
ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb 69.07s user 1.67s system 153% cpu 46.184 total
$ ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb
length([1], [2], [3])
5589.9316946266945
34533.239095516146
231867.74494217327
984638.8909954021
152500038.32994568
248342994.47921464
251351174.66099826
251130608.74878356
252898060.44766814
251565326.52146098
252531551.36269242
252679902.65561467
252857790.2371508
252777988.7473678
252773591.761745
length(*ARRAYS)
203424.36308847004
1244070.9415690985
9075393.587656023
22396469.65784431
22658642.224677842
23013820.973089136
23568321.130024165
23983927.519351605
24050318.72254725
24193566.145432606
23946959.208307654
24218444.78720826
24216814.78957417
24020154.628739387
length({a: 1}, {b: 2}, {c: 3})
139955.64061942746
712860.433643003
70809512.16772208
72854165.16527563
72921790.26188865
72899315.9428016
72870951.6581218
72826299.95749447
72898989.7902378
72833300.79168707
72823935.86139454
72847362.9304587
72912501.2264503
length(*HASHES)
609324.4189657518
2739081.0473220125
23254545.008583978
23860473.34556739
23869043.800744545
23554849.64225734
23848893.986106265
23698915.07949025
23746165.428700417
23830544.382198863
23852853.4068458
23816697.39566984
23854691.84671078
ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb 68.19s user 1.90s system 152% cpu 46.069 total
Current master, WITH ruby2_keywords checks:
Diff: https://github.com/oracle/truffleruby/commit/d143af3626aae009e2414bfe61833565fe3a0476
$ ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb
length([1], [2], [3])
12603.558417888466
53409.62050536004
370516.4425068324
1239974.7434903043
242192592.08090785
245773646.00306112
252383319.05233258
253003783.70782185
253146074.3832699
253120204.35549954
253085120.328254
253223113.68256786
253162927.8176365
253169591.94288176
253117609.5019953
length(*ARRAYS)
275432.96637055185
1447576.6571806432
19757793.228352327
21244902.41062589
21168748.14826498
21510511.327586602
21116717.4364119
22221398.681982987
22314928.523624208
22314794.71370992
22405375.122704845
22446519.020403787
22457491.078884233
length({a: 1}, {b: 2}, {c: 3})
129577.62376881254
757359.2144306883
70540237.6333344
70875244.57778414
71864146.83369508
71891423.33141543
71736995.55879919
71878798.78803566
71872829.0333677
71887237.86228648
71870155.40449627
71750903.20504545
71775982.89207047
length(*HASHES)
414011.9180097705
2166838.3517752853
21063991.318410262
22350677.08024464
21454963.511822302
21936072.442927938
22175774.47012569
22171105.696353428
22402636.31351625
21087394.755439878
22625056.38571944
22426332.52232551
22467747.630526073
ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb 68.35s user 1.99s system 154% cpu 45.665 total
$ ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb
length([1], [2], [3])
14502.107253278857
64006.27651673593
474919.89483105415
145386256.5254117
251549988.98723397
252887524.78630543
250750355.40115938
244728768.1731206
253118556.96940276
253107452.9354946
252568891.27054393
252522279.42764336
252570910.51856387
252530706.60648477
length(*ARRAYS)
270682.72777978046
1525579.2027933293
10289138.48320862
21555493.432529073
21041055.00691124
21547443.561254837
22197444.41637897
22405272.32619239
22222285.192590218
22550339.834661473
22607629.37794365
22432494.989741385
22659332.56763047
22687755.174301602
length({a: 1}, {b: 2}, {c: 3})
136332.97839624013
735058.5329440893
4391974.5084337
69787320.2923192
72172889.5642566
71717155.52212492
72117536.49006166
72200770.05842493
72108127.9289114
72139671.80287915
72142261.84497823
72118825.55495678
72127039.40424635
72137809.24708867
length(*HASHES)
391089.573999489
1980418.2624401646
20822027.10743342
22848211.991512418
22859804.761477154
22792469.43833811
22762841.750150904
22764791.214131076
22827581.16108274
22783240.735333785
22832119.824051525
22834968.50722559
22859054.448536437
ruby --disable-gems bench/benchmark --simple bench/micro/kwargs2.rb 70.01s user 2.70s system 159% cpu 45.725 total
@eregon
Copy link
Author

eregon commented Nov 24, 2019

Taking the last measurement for each.

TruffleRuby vs TruffleRuby with ruby2_keywords check

Diff: oracle/truffleruby@d143af3

  • length([1], [2], [3]): 252773591.761745/252530706.60648477 => 1.0009618044416226, 0.1% slower
  • length(*ARRAYS): 24020154.628739387/22687755.174301602 => 1.0587276900778175, 5.9% slower
  • length({a: 1}, {b: 2}, {c: 3}): 72912501.2264503/72137809.24708867 => 1.0107390560851124, 1% slower
  • length(*HASHES): 23854691.84671078/22859054.448536437 => 1.0435554935317146, 4.4% slower

2.7.0preview3 vs 2.6.5

  • length([1], [2], [3]): 5208503.015645484 / 5067702.542797175 => 1.0277838866151352, 2.7 is 2.8% slower
  • length(*ARRAYS): 8804729.284255322 / 7894752.6805929225 => 1.1152634718880208, 2.7 is 11.5% slower
  • length({a: 1}, {b: 2}, {c: 3}): 4130858.984293666 / 4399486.446482789 => 0.9389411774631379, 2.7 is 6.1% faster (faster Hash allocs?)
  • length(*HASHES): 8656855.986886652 / 7851394.039136068 => 1.1025883994276275, 2.7 is 10.3% slower

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment