Skip to content

Instantly share code, notes, and snippets.

@baweaver
Last active April 27, 2018 08:29
Show Gist options
  • Save baweaver/0869255d7325000c4c9bca5c836aef3c to your computer and use it in GitHub Desktop.
Save baweaver/0869255d7325000c4c9bca5c836aef3c to your computer and use it in GitHub Desktop.
Qo is faster than non-optimized vanilla Ruby in most cases in its evil compiled variant. See: https://github.com/baweaver/qo/blob/evil/lib/qo/evil/matcher.rb
➜ q git:(evil) ✗ rake perf
Running on Qo v0.2.1 at commit 341d3eab041a0aa2dae9fec8976cf0aeb5fe46e9
2.5.1
variables: {}
match_query: /Rob/.match?(target[0]) && (15..25).include?(target[1])
target: ["Robert", 22]
bind.local_variables: [:target, :bind, :compiled_matchers, :variables, :match_query]
Array size: 4000
Qo.and == Qo EVIL: true
Qo EVIL == Normal: true
Array * Array - Select index pattern match
==========================================
Warming up --------------------------------------
Vanilla 16.000 i/100ms
Vanilla HAX 123.000 i/100ms
Qo.and 9.000 i/100ms
Qo EVIL 79.000 i/100ms
Calculating -------------------------------------
Vanilla 165.575 (± 3.0%) i/s - 832.000 in 5.029422s
Vanilla HAX 1.215k (± 2.9%) i/s - 6.150k in 5.067108s
Qo.and 94.868 (± 3.2%) i/s - 477.000 in 5.032422s
Qo EVIL 797.948 (± 2.5%) i/s - 4.029k in 5.052419s
Comparison:
Vanilla HAX: 1214.8 i/s
Qo EVIL: 797.9 i/s - 1.52x slower
Vanilla: 165.6 i/s - 7.34x slower
Qo.and: 94.9 i/s - 12.80x slower
variables: {}
match_query: /Rob/.match?(target[:name]) && (15..25).include?(target[:age])
target: {:name=>"Robert", :age=>22}
bind.local_variables: [:target, :bind, :compiled_matchers, :variables, :match_query]
Array size: 4000
Qo.and == Qo EVIL: true
Qo EVIL == Normal: true
Hash * Hash - Hash intersection
===============================
Warming up --------------------------------------
Vanilla 49.000 i/100ms
Qo.and 7.000 i/100ms
Qo EVIL 76.000 i/100ms
Calculating -------------------------------------
Vanilla 499.699 (± 3.4%) i/s - 2.499k in 5.006433s
Qo.and 74.529 (± 2.7%) i/s - 378.000 in 5.076287s
Qo EVIL 762.847 (± 2.0%) i/s - 3.876k in 5.083081s
Comparison:
Qo EVIL: 762.8 i/s
Vanilla: 499.7 i/s - 1.53x slower
Qo.and: 74.5 i/s - 10.24x slower
Hash matches Object
variables: {}
match_query: /Rob/.match?(target.name) && (15..25).include?(target.age)
target: #<struct Person name="Robert", age=22>
bind.local_variables: [:target, :bind, :compiled_matchers, :variables, :match_query]
Array size: 4000
Qo.and == Qo EVIL: true
Qo EVIL == Normal: true
Hash * Object - Property match
==============================
Warming up --------------------------------------
Vanilla 51.000 i/100ms
Qo.and 8.000 i/100ms
Qo EVIL 77.000 i/100ms
Calculating -------------------------------------
Vanilla 507.204 (± 2.8%) i/s - 2.550k in 5.031802s
Qo.and 81.552 (± 2.5%) i/s - 408.000 in 5.006237s
Qo EVIL 782.593 (± 2.0%) i/s - 3.927k in 5.020002s
Comparison:
Qo EVIL: 782.6 i/s
Vanilla: 507.2 i/s - 1.54x slower
Qo.and: 81.6 i/s - 9.60x slower
@baweaver
Copy link
Author

Noted that this is the evil variant, and it most certainly is evil.

Tests are here: https://github.com/baweaver/qo/blob/evil/Rakefile

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