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

Replace x.times.map{} with Array.new(x){} in AD::Journey::Path::Pattern #22890

Merged
merged 1 commit into from Jan 3, 2016

Conversation

Projects
None yet
2 participants
@DNNX
Contributor

DNNX commented Jan 2, 2016

The former is more readable, performant and has fewer method calls.

Benchmark.ips do |x|
  x.report('times.map') { 5.times.map{} }
  x.report('Array.new') { Array.new(5){} }
  x.compare!
end
__END__
Calculating -------------------------------------
           times.map    21.188k i/100ms
           Array.new    30.449k i/100ms
-------------------------------------------------
           times.map    311.613k (± 3.5%) i/s -      1.568M
           Array.new    590.374k (± 1.2%) i/s -      2.954M

Comparison:
           Array.new:   590373.6 i/s
           times.map:   311612.8 i/s - 1.89x slower
Replace x.times.map{} with Array.new(x){}
The former is slightly more readable, performant and has fewer method calls.

```ruby
Benchmark.ips do |x|
  x.report('times.map') { 5.times.map{} }
  x.report('Array.new') { Array.new(5){} }
  x.compare!
end
__END__
Calculating -------------------------------------
           times.map    21.188k i/100ms
           Array.new    30.449k i/100ms
-------------------------------------------------
           times.map    311.613k (± 3.5%) i/s -      1.568M
           Array.new    590.374k (± 1.2%) i/s -      2.954M

Comparison:
           Array.new:   590373.6 i/s
           times.map:   311612.8 i/s - 1.89x slower
```

spastorino added a commit that referenced this pull request Jan 3, 2016

Merge pull request #22890 from DNNX/times-map
Replace x.times.map{} with Array.new(x){} in AD::Journey::Path::Pattern

@spastorino spastorino merged commit 3d590ad into rails:master Jan 3, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@DNNX DNNX referenced this pull request Jan 5, 2016

Merged

New Performance/TimesMap cop #2583

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment