Skip to content

Loading…

performance improvement pg_copy_to_string - change the way concat string #8

Merged
merged 1 commit into from

2 participants

@ermolaev
require 'benchmark'

Benchmark.bm do |b| 
  b.report('+=') do
    data = ''
    line = 'hello word'

    100_000.times { data += line}
  end

  b.report('<<') do
    data = ''
    line = 'hello word'

    100_000.times { data << line}
  end

end
       user     system      total        real
+=  8.750000  13.420000  22.170000 ( 22.236511)
<<  0.010000   0.000000   0.010000 (  0.014012)
@diogob diogob merged commit 66c159d into diogob:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2013
  1. performance improvement pg_copy_to_string

    ermolaev committed
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/postgres-copy/active_record.rb
View
2 lib/postgres-copy/active_record.rb
@@ -24,7 +24,7 @@ def self.pg_copy_to path = nil, options = {}
# Copy all data to a single string
def self.pg_copy_to_string options = {}
data = ''
- self.pg_copy_to(nil, options){|l| data += l }
+ self.pg_copy_to(nil, options){|l| data << l }
if options[:format] == :binary
data.force_encoding("ASCII-8BIT")
end
Something went wrong with that request. Please try again.