Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active September 27, 2019 17:37
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 havenwood/588c7a941bf967b46bfcedce1baccffc to your computer and use it in GitHub Desktop.
Save havenwood/588c7a941bf967b46bfcedce1baccffc to your computer and use it in GitHub Desktop.
RougeRRR
require 'benchmark/ips'
require 'set'
Benchmark.ips do |x|
empty = []
exact = %w[foo]
match = %w[foo bar]
short = %w[bar baz]
exact_set = Set['foo']
x.report('Set empty') { empty.to_set > exact_set }
x.report('Set exact') { exact.to_set > exact_set }
x.report('Set match') { match.to_set > exact_set }
x.report('Set short') { short.to_set > exact_set }
x.report('Reg empty') { empty.size > 1 && empty.include?('foo') }
x.report('Reg exact') { exact.size > 1 && exact.include?('foo') }
x.report('Reg match') { match.size > 1 && match.include?('foo') }
x.report('Reg short') { short.size > 1 && short.include?('foo') }
x.compare!
end
Warming up --------------------------------------
Set empty 60.556k i/100ms
Set exact 49.552k i/100ms
Set match 44.953k i/100ms
Set short 43.193k i/100ms
Reg empty 347.789k i/100ms
Reg exact 342.195k i/100ms
Reg match 259.546k i/100ms
Reg short 250.949k i/100ms
Calculating -------------------------------------
Set empty 775.286k (± 4.9%) i/s - 3.876M in 5.011502s
Set exact 621.709k (± 3.7%) i/s - 3.122M in 5.028296s
Set match 508.784k (± 4.4%) i/s - 2.562M in 5.045856s
Set short 505.296k (± 3.5%) i/s - 2.548M in 5.049707s
Reg empty 15.720M (± 3.1%) i/s - 78.600M in 5.005120s
Reg exact 15.796M (± 4.2%) i/s - 79.047M in 5.013349s
Reg match 7.510M (± 5.0%) i/s - 37.634M in 5.024517s
Reg short 6.638M (± 3.5%) i/s - 33.376M in 5.034252s
Comparison:
Reg exact: 15796054.6 i/s
Reg empty: 15719866.3 i/s - same-ish: difference falls within error
Reg match: 7509807.0 i/s - 2.10x slower
Reg short: 6638315.4 i/s - 2.38x slower
Set empty: 775285.6 i/s - 20.37x slower
Set exact: 621709.0 i/s - 25.41x slower
Set match: 508784.1 i/s - 31.05x slower
Set short: 505296.2 i/s - 31.26x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment