Skip to content

Instantly share code, notes, and snippets.

@fidothe
Created November 11, 2019 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fidothe/7d76f60cf2adbb8a2aab8adf21f40192 to your computer and use it in GitHub Desktop.
Save fidothe/7d76f60cf2adbb8a2aab8adf21f40192 to your computer and use it in GitHub Desktop.
Benchmark gsub/sub before and after https://github.com/jruby/jruby/pull/5952
BEFORE:
jruby [master] $ benchmark bench/core/string/bench_gsub.rb
Warming up --------------------------------------
gsub-string 83.418k i/100ms
gsub-regex 120.922k i/100ms
gsub-regex-block 82.905k i/100ms
gsub-string 96.724k i/100ms
gsub-regex 128.786k i/100ms
gsub-regex-block 83.732k i/100ms
gsub-string 100.446k i/100ms
gsub-regex 117.749k i/100ms
gsub-regex-block 81.020k i/100ms
Calculating -------------------------------------
gsub-string 1.864M (± 5.2%) i/s - 9.341M in 5.028109s
gsub-regex 2.821M (± 6.4%) i/s - 14.012M in 4.997615s
gsub-regex-block 1.580M (± 3.9%) i/s - 7.940M in 5.033951s
gsub-string 1.843M (± 6.2%) i/s - 9.241M in 5.038603s
gsub-regex 2.867M (± 4.3%) i/s - 14.365M in 5.020753s
gsub-regex-block 1.573M (± 5.1%) i/s - 7.859M in 5.009079s
gsub-string 1.901M (± 3.9%) i/s - 9.542M in 5.028879s
gsub-regex 2.805M (± 7.5%) i/s - 14.012M in 5.027708s
gsub-regex-block 1.557M (± 5.4%) i/s - 7.778M in 5.012116s
Comparison:
gsub-regex: 2805333.0 i/s
gsub-string: 1900607.3 i/s - 1.48x slower
gsub-regex-block: 1556662.7 i/s - 1.80x slower
AFTER:
jruby [use-string-matching-5905] $ benchmark bench/core/string/bench_gsub.rb
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.headius.backport9.modules.Modules to method sun.nio.ch.NativeThread.signal(long)
WARNING: Please consider reporting this to the maintainers of com.headius.backport9.modules.Modules
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Warming up --------------------------------------
gsub-string 132.304k i/100ms
gsub-regex 134.161k i/100ms
gsub-regex-block 98.747k i/100ms
gsub-string 146.478k i/100ms
gsub-regex 137.456k i/100ms
gsub-regex-block 97.131k i/100ms
gsub-string 143.662k i/100ms
gsub-regex 140.012k i/100ms
gsub-regex-block 96.690k i/100ms
Calculating -------------------------------------
gsub-string 2.899M (± 5.5%) i/s - 14.510M in 5.022088s
gsub-regex 2.876M (± 8.2%) i/s - 14.281M in 5.012498s
gsub-regex-block 1.689M (± 5.3%) i/s - 8.412M in 4.998477s
gsub-string 2.967M (± 5.0%) i/s - 14.797M in 5.001599s
gsub-regex 2.984M (± 5.0%) i/s - 14.981M in 5.035178s
gsub-regex-block 1.671M (± 5.6%) i/s - 8.412M in 5.051254s
gsub-string 3.084M (± 3.8%) i/s - 15.515M in 5.039117s
gsub-regex 2.894M (± 6.9%) i/s - 14.421M in 5.009674s
gsub-regex-block 1.738M (± 3.6%) i/s - 8.702M in 5.013762s
Comparison:
gsub-string: 3083819.2 i/s
gsub-regex: 2893563.9 i/s - same-ish: difference falls within error
gsub-regex-block: 1737972.1 i/s - 1.77x slower
BEFORE:
jruby [use-string-matching-5905] $ benchmark bench/core/string/bench_sub.rb
Warming up --------------------------------------
sub-string 85.531k i/100ms
sub-regex 115.471k i/100ms
sub-regex-block 86.421k i/100ms
sub-string 112.434k i/100ms
sub-regex 139.722k i/100ms
sub-regex-block 89.876k i/100ms
sub-string 101.295k i/100ms
sub-regex 138.565k i/100ms
sub-regex-block 87.712k i/100ms
Calculating -------------------------------------
sub-string 2.190M (± 7.6%) i/s - 10.940M in 5.025020s
sub-regex 3.122M (± 8.9%) i/s - 15.519M in 5.017819s
sub-regex-block 1.648M (± 6.9%) i/s - 8.245M in 5.030430s
sub-string 2.255M (± 5.5%) i/s - 11.244M in 5.002959s
sub-regex 3.310M (± 3.5%) i/s - 16.628M in 5.029668s
sub-regex-block 1.654M (± 5.9%) i/s - 8.245M in 5.003373s
sub-string 2.301M (± 5.5%) i/s - 11.548M in 5.036839s
sub-regex 3.263M (± 6.5%) i/s - 16.351M in 5.033664s
sub-regex-block 1.689M (± 3.8%) i/s - 8.508M in 5.044707s
Comparison:
sub-regex: 3263463.5 i/s
sub-string: 2300856.5 i/s - 1.42x slower
sub-regex-block: 1689094.8 i/s - 1.93x slower
AFTER:
jruby [use-string-matching-5905] $ benchmark bench/core/string/bench_sub.rb
Warming up --------------------------------------
sub-string 130.911k i/100ms
sub-regex 132.331k i/100ms
sub-regex-block 97.297k i/100ms
sub-string 142.288k i/100ms
sub-regex 138.834k i/100ms
sub-regex-block 93.862k i/100ms
sub-string 140.333k i/100ms
sub-regex 134.390k i/100ms
sub-regex-block 96.066k i/100ms
Calculating -------------------------------------
sub-string 3.286M (± 6.1%) i/s - 16.419M in 5.016219s
sub-regex 3.343M (± 5.4%) i/s - 16.664M in 5.000450s
sub-regex-block 1.894M (± 5.9%) i/s - 9.511M in 5.041052s
sub-string 2.969M (±16.2%) i/s - 14.454M in 5.039208s
sub-regex 3.049M (±15.4%) i/s - 14.917M in 5.025439s
sub-regex-block 1.858M (± 5.2%) i/s - 9.318M in 5.031101s
sub-string 3.383M (± 5.1%) i/s - 16.980M in 5.033060s
sub-regex 3.312M (± 6.6%) i/s - 16.530M in 5.015668s
sub-regex-block 1.891M (± 5.0%) i/s - 9.511M in 5.042478s
Comparison:
sub-string: 3383455.0 i/s
sub-regex: 3312195.3 i/s - same-ish: difference falls within error
sub-regex-block: 1891378.7 i/s - 1.79x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment