Last active
December 15, 2015 02:48
-
-
Save kostya/5189457 to your computer and use it in GitHub Desktop.
tt1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Gemfile.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source :rubygems | |
| gem 'activerecord', '~>3.2' | |
| gem 'pg' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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