Skip to content

Instantly share code, notes, and snippets.

@kostya
Last active December 15, 2015 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kostya/5189457 to your computer and use it in GitHub Desktop.
Save kostya/5189457 to your computer and use it in GitHub Desktop.
tt1
Gemfile.lock
source :rubygems
gem 'activerecord', '~>3.2'
gem 'pg'
require 'rubygems'
require 'bundler/setup'
require 'active_record'
conn = {:adapter => 'postgresql', :database => "tt_test", :pool => 30, :allow_concurrency => true}
`dropdb tt_test`
`createdb tt_test`
ActiveRecord::Base.establish_connection conn
ActiveRecord::Migration.create_table(:bla){|t| t.integer :a; t.string :b }
class Bla < ActiveRecord::Base; self.table_name = 'bla'; end
T = 10
N = 100
T.times do |i|
Bla.create! :a => i, :b => "bla#{i}"
end
tm1 = Time.now
(0...T).map do |i|
Thread.new do
bla = Bla.find_by_a(i)
bla.b = bla.b + "i"
bla.save!
end
end.each(&:join)
puts Time.now - tm1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment