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

Improve Array#concat performance if only one argument is given #1634

Closed
wants to merge 1 commit into from

Conversation

Watson1978
Copy link
Contributor

This is very similar with #1631
If only one argument is given, this will concatenate the array without
generating temporary Array object.

Array#concat will be faster around 19%

  • Before
Calculating -------------------------------------
        Array#concat      2.187M (± 3.5%) i/s -     10.926M in   5.002829s
  • After
Calculating -------------------------------------
        Array#concat      2.598M (± 1.8%) i/s -     13.008M in   5.008201s
  • Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "Array#concat" do |i|
    other = [4]
    i.times { [1, 2, 3].concat(other) }
  end
end

This is very similar with ruby#1631
If only one argument is given, this will concatenate the array without
generating temporary Array object.

Array#concat will be faster around 19%

* Before
Calculating -------------------------------------
        Array#concat      2.187M (± 3.5%) i/s -     10.926M in   5.002829s

* After
Calculating -------------------------------------
        Array#concat      2.598M (± 1.8%) i/s -     13.008M in   5.008201s

* Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "Array#concat" do |i|
    other = [4]
    i.times { [1, 2, 3].concat(other) }
  end
end
@hsbt hsbt closed this in 6270d59 May 26, 2017
Watson1978 added a commit to Watson1978/ruby that referenced this pull request Jul 27, 2017
This is very similar with ruby#1634
If only one argument is given, this will prepend the string without
generating temporary object.

```
String#prepend -> 47.5 % up
```

### Before
```
      String#prepend      1.517M (± 1.8%) i/s -      7.614M in   5.019819s
```

### After
```
      String#prepend      2.236M (± 3.4%) i/s -     11.234M in   5.029716s
```

### Test code
```
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "String#prepend" do |loop|
    loop.times { "!".prepend("hello") }
  end
end
```
@Watson1978 Watson1978 deleted the array_concat branch October 14, 2017 12:36
Watson1978 added a commit to Watson1978/ruby that referenced this pull request Oct 14, 2017
This is very similar with ruby#1634
If only one argument is given, this will prepend the string without
generating temporary object.

```
String#prepend -> 47.5 % up
```

```
      String#prepend      1.517M (± 1.8%) i/s -      7.614M in   5.019819s
```

```
      String#prepend      2.236M (± 3.4%) i/s -     11.234M in   5.029716s
```

```
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "String#prepend" do |loop|
    loop.times { "!".prepend("hello") }
  end
end
```
Watson1978 added a commit to Watson1978/ruby that referenced this pull request Oct 27, 2017
This is very similar with ruby#1634
If only one argument is given, this will prepend the string without
generating temporary object.

```
String#prepend -> 47.5 % up
```

```
      String#prepend      1.517M (± 1.8%) i/s -      7.614M in   5.019819s
```

```
      String#prepend      2.236M (± 3.4%) i/s -     11.234M in   5.029716s
```

```
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "String#prepend" do |loop|
    loop.times { "!".prepend("hello") }
  end
end
```
matzbot pushed a commit that referenced this pull request Oct 27, 2017
…given

* string.c (rb_str_prepend_multi): Prepend the string without generating
    temporary String object if only one argument is given.
	This is very similar with #1634

	String#prepend -> 47.5 % up

    [Fix GH-1670] [ruby-core:82195] [Bug #13773]

* Before
      String#prepend      1.517M (± 1.8%) i/s -      7.614M in   5.019819s

* After
      String#prepend      2.236M (± 3.4%) i/s -     11.234M in   5.029716s

* Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "String#prepend" do |loop|
    loop.times { "!".prepend("hello") }
  end
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
mrkn pushed a commit to mrkn/ruby that referenced this pull request Dec 1, 2017
…given

* string.c (rb_str_prepend_multi): Prepend the string without generating
    temporary String object if only one argument is given.
	This is very similar with ruby#1634

	String#prepend -> 47.5 % up

    [Fix rubyGH-1670] [ruby-core:82195] [Bug #13773]

* Before
      String#prepend      1.517M (± 1.8%) i/s -      7.614M in   5.019819s

* After
      String#prepend      2.236M (± 3.4%) i/s -     11.234M in   5.029716s

* Test code
require 'benchmark/ips'

Benchmark.ips do |x|
  x.report "String#prepend" do |loop|
    loop.times { "!".prepend("hello") }
  end
end

git-svn-id: svn+ssh://svn.ruby-lang.org/ruby/trunk@60480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants