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 initialization of array #10318

Merged
merged 1 commit into from
Apr 23, 2013

Conversation

vipulnsward
Copy link
Member

refactor statements

@dmathieu
Copy link
Contributor

This is only a cosmetic change. Those aren't usually merged, sorry.

@vipulnsward
Copy link
Member Author

How is this cosmetic? Its a bit faster, losing 2 operations.

@vipulnsward
Copy link
Member Author

@dmathieu just for ref: https://gist.github.com/vipulnsward/768bcf54ed67dbac4b06
It would be fine if this gets rejected to maintain code-style maybe.

guilleiguaran added a commit that referenced this pull request Apr 23, 2013
@guilleiguaran guilleiguaran merged commit 1bd92ed into rails:master Apr 23, 2013
@vipulnsward vipulnsward deleted the refactor_obvious branch April 23, 2013 13:57
@dmathieu
Copy link
Contributor

I don't think this kind of micro optimization is worth the change. It really has a very small impact.

@siong1987
Copy link
Contributor

require "benchmark"

Benchmark.bm(7) do |x|
  x.report("before:")   do
    (1..100000).each do
      method = []
      method << "value = nil"
      method << "halted = false"
    end
  end
  x.report("after:") do
    (1..100000).each do
      method =  ["value = nil", "halted = false"]
    end
  end
end

              user     system      total        real
before:   0.090000   0.000000   0.090000 (  0.092787)
after:    0.080000   0.000000   0.080000 (  0.078116)

You are right. But, it seems like it also makes the code cleaner. Not worth a huge debate over it tho.

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

4 participants