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

Refactor Mime::Type #7522

Merged
merged 1 commit into from Sep 4, 2012
Merged

Refactor Mime::Type #7522

merged 1 commit into from Sep 4, 2012

Conversation

lexmag
Copy link
Contributor

@lexmag lexmag commented Sep 4, 2012

parse method performance improvements - ~27-33%

@rafaelfranca
Copy link
Member

Where is the benchmark?

@@ -4,7 +4,7 @@
module Mime
class Mimes < Array
def symbols
@symbols ||= map {|m| m.to_sym }
@symbols ||= map(&:to_sym)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only to simplify

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to make it faster this is making a little slower:

              user     system      total        real
block     1.680000   0.000000   1.680000 (  1.677796)
sym to    1.840000   0.000000   1.840000 (  1.850888)
[1.9.3-p194 placar-admin (master)]$ ruby bm.rb 
              user     system      total        real
block     1.680000   0.000000   1.680000 (  1.680283)
sym to    1.870000   0.000000   1.870000 (  1.873345)
[1.9.3-p194 placar-admin (master)]$ ruby bm.rb 
              user     system      total        real
block     1.700000   0.000000   1.700000 (  1.707954)
sym to    1.860000   0.000000   1.860000 (  1.868167)
[1.9.3-p194 placar-admin (master)]$ ruby bm.rb 
              user     system      total        real
block     1.860000   0.000000   1.860000 (  1.874244)
sym to    1.930000   0.000000   1.930000 (  1.933034)
[1.9.3-p194 placar-admin (master)]$ ruby bm.rb 
              user     system      total        real
block     1.680000   0.010000   1.690000 (  1.677366)
sym to    1.850000   0.000000   1.850000 (  1.857757)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've return explicit block.

@lexmag
Copy link
Contributor Author

lexmag commented Sep 4, 2012

accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,  , pronto/1.00.00, sslvpn/1.00.00.00, */*"

Benchmark.measure{ 1_000_0.times { Mime::Type.parse(accept) }}

old: 1.430000   0.000000   1.430000 (  1.440977)
new: 0.920000   0.000000   0.920000 (  0.921813)

@rafaelfranca
Copy link
Member

@lexmag I'm fine with the changes. I'm just wondering about the order -> index change and the explicit block -> symbol to proc change.

Also coul you add this benchmark in the commit message?

@lexmag
Copy link
Contributor Author

lexmag commented Sep 4, 2012

I've added benchmark in the commit message.

`parse` method performance improvements - ~27-33%:

    accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,  , pronto/1.00.00, sslvpn/1.00.00.00, */*"

    Benchmark.measure{ 1_000_0.times { Mime::Type.parse(accept) }}

    old: 1.430000   0.000000   1.430000 (  1.440977)
    new: 0.920000   0.000000   0.920000 (  0.921813)
@rafaelfranca
Copy link
Member

Thank you so much.

rafaelfranca added a commit that referenced this pull request Sep 4, 2012
@rafaelfranca rafaelfranca merged commit 7995c03 into rails:master Sep 4, 2012
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.

None yet

2 participants