Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Merge requests
  • !7999

Merged
Created Oct 09, 2014 by Administrator@rootOwner

Append in place for strings and arrays [failure unrelated]

  • Overview 16
  • Commits 1
  • Changes 14

Created by: cirosantilli

It's faster.

Behavior should be unchanged: no function inputs were altered, only local variables.

Benchmark:

Benchmark.bm(first_col_width) do |benchmark|
  benchmark.report('+= [0]') do
    a = []
    N.times { a += [0] }
  end

  benchmark.report('<< 0') do
    a = []
    N.times { a << 0 }
  end

  benchmark.report('<< [0, 1]') do
    a = []
    N.times { a += [0, 1] }
  end

  benchmark.report('push(*[0, 1])') do
    a = []
    N.times { a.push(*[0, 1]) }
  end

  benchmark.report('+= "ab"') do
    a = ''
    N.times { a += 'ab' }
  end

  benchmark.report('<< "ab"') do
    a = []
    N.times { a << 'ab' }
  end
end

Result:

                    user     system      total        real
+= [0]             0.090000   0.010000   0.100000 (  0.093640)
<< 0               0.000000   0.000000   0.000000 (  0.000706)
<< [0, 1]          0.170000   0.000000   0.170000 (  0.164410)
push(*[0, 1])      0.000000   0.000000   0.000000 (  0.001339)
+= "ab"            0.020000   0.000000   0.020000 (  0.024198)
<< "ab"            0.000000   0.000000   0.000000 (  0.001242)
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: github/fork/cirosantilli/append-inplace