Project

General

Profile

Actions

Bug #13773

closed

Improve String#prepend performance if only one argument is given

Added by watson1978 (Shizuo Fujita) over 6 years ago. Updated over 6 years ago.

Status:
Closed
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

Actions

Also available in: Atom PDF

Like0
Like0