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

Remove overhead of surrounding block from length-vs-size-vs-count benchmark #97

Closed

Conversation

radarek
Copy link

@radarek radarek commented Jan 25, 2016

See #96 for detailed explanation

Before:

ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
Calculating -------------------------------------
        Array#length   135.292k i/100ms
          Array#size   137.775k i/100ms
         Array#count   132.586k i/100ms
-------------------------------------------------
        Array#length      9.906M (± 7.6%) i/s -     49.246M
          Array#size     10.038M (± 6.0%) i/s -     50.012M
         Array#count      8.399M (± 6.0%) i/s -     41.897M

Comparison:
          Array#size: 10038186.0 i/s
        Array#length:  9905809.3 i/s - 1.01x slower
         Array#count:  8399076.6 i/s - 1.20x slower

After:

ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
Calculating -------------------------------------
        Array#length    10.290k i/100ms
          Array#size    10.301k i/100ms
         Array#count     3.649k i/100ms
-------------------------------------------------
        Array#length    111.847k (± 2.0%) i/s -    565.950k
          Array#size    112.374k (± 2.0%) i/s -    566.555k
         Array#count     37.865k (± 2.1%) i/s -    189.748k

Comparison:
          Array#size:   112373.6 i/s
        Array#length:   111847.4 i/s - 1.00x slower
         Array#count:    37865.1 i/s - 2.97x slower

@nateberkopec
Copy link
Collaborator

👍 We should probably write something down, maybe in Contributing.md, about preferring this style where possible.

x.report("Array#count") { ARRAY.count }
x.report("Array#length", "$array.length;" * 1_000)
x.report("Array#size", "$array.size;" * 1_000)
x.report("Array#count", "$array.count;" * 1_000)
Copy link

Choose a reason for hiding this comment

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

Why are you using a global variable instead of the ARRAY constant?

@benoittgt
Copy link

benoittgt commented Jan 18, 2017

What is the status of this PR? I can work on that.

@etagwerker
Copy link
Member

@benoittgt I believe no one has worked on this for years. Feel free to take a stab at it. 👍🏼

@etagwerker
Copy link
Member

Closing this because it has had no activity in years. Feel free to re-open if you get to time to address the comments. Thanks!

@etagwerker etagwerker closed this Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants