Project

General

Profile

Bug #13773

Improve String#prepend performance if only one argument is given

Added by watson1978 (Shizuo Fujita) about 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:82195]

Description

This is very similar with https://github.com/ruby/ruby/pull/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

Patch

https://github.com/ruby/ruby/pull/1670

Associated revisions

Revision b03a44c4
Added by watson1978 (Shizuo Fujita) almost 2 years ago

string.c: Improve String#prepend performance if only one argument is 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 https://github.com/ruby/ruby/pull/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

Revision 60480
Added by watson1978 (Shizuo Fujita) almost 2 years ago

string.c: Improve String#prepend performance if only one argument is 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 https://github.com/ruby/ruby/pull/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

Revision 60480
Added by watson1978 (Shizuo Fujita) almost 2 years ago

string.c: Improve String#prepend performance if only one argument is 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 https://github.com/ruby/ruby/pull/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

Revision 60480
Added by watson1978 (Shizuo Fujita) almost 2 years ago

string.c: Improve String#prepend performance if only one argument is 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 https://github.com/ruby/ruby/pull/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

History

#1

Updated by watson1978 (Shizuo Fujita) almost 2 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r60480.


string.c: Improve String#prepend performance if only one argument is 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 https://github.com/ruby/ruby/pull/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

Also available in: Atom PDF