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

Use block variable instead of global #20486

Merged
merged 1 commit into from Jun 9, 2015

Conversation

repinel
Copy link
Member

@repinel repinel commented Jun 9, 2015

Similar to #20410

Benchmark.ips do |x|
  x.report("$&") {
    "foo".gsub(/f/) { $&.hex }
  }
  x.report("block var") {
    "foo".gsub(/f/) { |match| match.hex }
  }
end
Calculating -------------------------------------
                  $&    23.271k i/100ms
           block var    24.804k i/100ms
-------------------------------------------------
                  $&    321.981k (± 7.4%) i/s -      1.606M
           block var    324.949k (± 9.2%) i/s -      1.612M

```ruby
Benchmark.ips do |x|
  x.report("$&") {
    "foo".gsub(/f/) { $&.hex }
  }
  x.report("block var") {
    "foo".gsub(/f/) { |match| match.hex }
  }
end
```

```
Calculating -------------------------------------
                  $&    23.271k i/100ms
           block var    24.804k i/100ms
-------------------------------------------------
                  $&    321.981k (± 7.4%) i/s -      1.606M
           block var    324.949k (± 9.2%) i/s -      1.612M
```
rafaelfranca added a commit that referenced this pull request Jun 9, 2015
@rafaelfranca rafaelfranca merged commit d0de07d into rails:master Jun 9, 2015
@repinel repinel deleted the improve-gsub-and-global-vars branch June 9, 2015 02: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.

None yet

2 participants