Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
ActiveRecord threaded benchmark
<pre class='prettyprint' language='ruby'>require 'rubygems' require 'active_record' require 'benchmark' ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => 'perf_ar.db' # set up ActiveRecord class ArItem < ActiveRecord::Base set_table_name 'items' end # created schema and data class NewItem < ActiveRecord::Migration def self.up create_table :items do |t| t.column :name, :string t.column :description, :text t.column :active, :boolean t.column :created_at, :datetime end end def self.down drop_table :items end end NewItem.up 1000.times do |i| ArItem.create(:name => "record_#{i}", :description => "test record", :active => i.remainder(3).zero?) end # run benchmarks Benchmark.bmbm do |x| x.report('active_record single-thread') do 100.times do ArItem.find(:all, :conditions => ["active = ?", false]) end end x.report('active_record threaded') do ActiveRecord::Base.allow_concurrency = true threads = [] 10.times do t = Thread.new do 10.times do ArItem.find(:all, :conditions => ["active = ?", false]) end end threads.push(t) end threads.each { |t| t.join } end end ActiveRecord::Base.verify_active_connections! NewItem.down</pre> <a href="http://www.refactormycode.com/codes/238-activerecord-threaded-benchmark" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>