Skip to content

Instantly share code, notes, and snippets.

View methodmissing's full-sized avatar

Lourens Naudé methodmissing

View GitHub Profile
213-138-231-57:extlib lourens$ jruby benchmarks/callsite.rb
Results |
---------------------------------------------------------
Object#callsite_with_constant_append 0.747 |
Object#callsite_without_constant_append 0.726 |
Object#callsite_with_constant_concat 0.674 |
Object#callsite_without_constant_concat 0.724 |
213-138-231-57:extlib lourens$ jruby --fast benchmarks/callsite.rb
Results |
---------------------------------------------------------
213-138-231-57:extlib lourens$ jruby benchmarks/callsite.rb
Results |
---------------------------------------------------------
Object#callsite_with_constant_append 0.741 |
Object#callsite_without_constant_append 0.667 |
Object#callsite_with_constant_concat 0.702 |
Object#callsite_without_constant_concat 0.700 |
213-138-231-57:extlib lourens$ jruby benchmarks/callsite.rb
Results |
---------------------------------------------------------
#!/usr/bin/env ruby
require "rubygems"
require "rbench"
class Object
CALLSITE_SAMPLE = 1..3
def callsite_with_constant_append( *signature )
( caller[CALLSITE_SAMPLE] << signature ).hash
2279161: cache cleared :13 Module#extend_object
2279161: cache cleared :13 Module#extend_object
2279161: c-return :13 Module#extend_object
2279161: c-call :13 Module#extended
2279161: c-return :13 Module#extended
2279161: c-return :13 Kernel#extend
2279161: return :14 Post#initialize
2279161: c-return :27 Class#new
2279161: call : 3 SpecialPost#save
2279161: line : 4 SpecialPost#save
diff --git a/lib/optimizations/associations/macro.rb b/lib/optimizations/associations/macro.rb
index 6d83873..f8a7d8c 100644
--- a/lib/optimizations/associations/macro.rb
+++ b/lib/optimizations/associations/macro.rb
@@ -25,6 +25,56 @@ module Scrooge
end
module SingletonMethods
+
+ def self.extended( base )
Processing HotelsController#index (for 127.0.0.1 at 2009-03-16 22:53:26) [GET]
Parameters: {"action"=>"index", "controller"=>"hotels"}
Hotel Columns (2.3ms) SHOW FIELDS FROM `hotels`
Hotel Load Scrooged (0.7ms) SELECT `hotels`.id FROM `hotels` LIMIT 0, 15
SQL (0.3ms) SELECT count(*) AS count_all FROM `hotels`
Rendering template within layouts/application
Rendering hotels/index
SQL (0.8ms) SELECT `hotels`.location_id,`hotels`.hotel_name,`hotels`.location,`hotels`.from_price,`hotels`.star_rating,`hotels`.apt,`hotels`.latitude,`hotels`.longitude,`hotels`.distance,`hotels`.narrative,`hotels`.telephone,`hotels`.important_notes,`hotels`.nearest_tube,`hotels`.nearest_rail,`hotels`.created_at,`hotels`.updated_at FROM `hotels` WHERE `hotels`.id = '8092'
Image Columns (1.9ms) SHOW FIELDS FROM `images`
Image Load Scrooged (0.5ms) SELECT `images`.id FROM `images` WHERE (`images`.hotel_id = 8092) LIMIT 1
def test_should_rollback_any_changes_if_an_exception_occurred_while_saving
before = [@pirate.catchphrase, @pirate.ship.name]
@pirate.catchphrase = 'Arr'
@pirate.ship.name = 'The Vile Insanity'
# Stub the save method of the @pirate.ship instance to raise an exception
class << @pirate.ship
def save(*args)
super
# Reset id and @new_record if the transaction rolls back.
def rollback_active_record_state!
id_present = has_attribute?(self.class.primary_key)
previous_id = id
previous_new_record = new_record?
yield
rescue Exception
@new_record = previous_new_record
if id_present
self.id = previous_id
macbook-pros-computer:scrooge lourens$ rake
(in /Users/lourens/projects/scrooge)
/opt/local/bin/ruby -Ilib:/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test:/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test/connections/native_mysql -r /Users/lourens/projects/scrooge/test/setup "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test/cases/aaa_create_tables_test.rb" "/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test/cases/adapter_test.rb" "/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test/cases/aggregations_test.rb" "/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test/cases/ar_schema_test.rb" "/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test/cases/associations/belongs_to_associations_test.rb" "/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test/cases/associations/callbacks_test.rb" "/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.1/test/cases/associations/cascaded_eager_loadin
Processing HomeController#show (for 127.0.0.1 at 2009-03-09 03:21:15) [GET]
Parameters: {"action"=>"show", "controller"=>"home"}
Continent Load (118.5ms) SELECT `continents`.id FROM `continents`
Rendering template within layouts/application
Rendering home/show
Rendered shared/_header (0.4ms)
Rendered shared/_navigation (0.7ms)
Missing template home/_show_sidebar.erb in view path app/views
Rendered shared/_sidebar (0.6ms)
Rendered shared/_footer (0.3ms)