Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify delete_param #1398

Merged
merged 1 commit into from
Oct 9, 2019
Merged

Conversation

styd
Copy link
Contributor

@styd styd commented Oct 9, 2019

Don't use compact to delete POST and GET params.

It seems that memoization and || is faster.

Benchmark.ips do |x|
  x.report 'compact -> first' do
    a = {a: 2, c: 4, d: 5}
    [a.delete(:a), a.delete(:b)].compact.first
    [a.delete(:b), a.delete(:c)].compact.first
    [a.delete(:c), a.delete(:d)].compact.first
  end

  x.report '||' do
    a = {a: 2, c: 4, d: 5}
    b, c = a.delete(:a), a.delete(:b)
    b || c
    b, c = a.delete(:b), a.delete(:c)
    b || c
    b, c = a.delete(:c), a.delete(:d)
    b || c
  end
  x.compare!
end
Warming up --------------------------------------
    compact -> first   101.688k i/100ms
                  ||   142.951k i/100ms
Calculating -------------------------------------
    compact -> first      1.285M (± 7.5%) i/s -      6.406M in   5.017583s
                  ||      1.970M (± 5.2%) i/s -      9.864M in   5.023221s

Comparison:
                  ||:  1969780.4 i/s
    compact -> first:  1285326.8 i/s - 1.53x  slower

@rafaelfranca rafaelfranca merged commit 91a02b2 into rack:master Oct 9, 2019
@styd styd deleted the improve-delete-param branch October 9, 2019 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants