Skip to content

Instantly share code, notes, and snippets.

@ferrous26
ferrous26 / bench.rb
Created March 15, 2012 05:22
Is it worth caching ActiveSupport::Inflector inflections that get used a lot
require 'benchmark'
Benchmark.bmbm do |bench|
regexp = /s$/i
empty = '' hash = {
'boxes' => 'box',
'windows' => 'window', 'buttons' => 'button',
'Buttons' => 'button',
'dialogs' => 'dialog'
}
@ferrous26
ferrous26 / bench_inspect.rb
Created March 10, 2012 08:12
For MacRuby pull request #60
require 'benchmark'
Benchmark.bmbm do |bench|
url = NSURL.URLWithString('http://macruby.org/')
set = NSSet.setWithArray([1,2,3])
bundle = NSBundle.mainBundle
freq = 100_000
bench.report('url#inspect') do |x|
@ferrous26
ferrous26 / other_code_path.diff
Created February 10, 2012 05:22
MacRuby does not use Syck
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index e873923..392c91b 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1921,12 +1921,12 @@ class Gem::Specification
end
def to_yaml(opts = {}) # :nodoc:
- if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? then
+ # XXX MACRUBY does not have syck, but does not have YAML::ENGINE either
@ferrous26
ferrous26 / better_fix.diff
Created February 9, 2012 08:22
Rubygems problem
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 567fb07..85a4995 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -6,8 +6,9 @@
#++
module Gem
- QUICKLOADER_SUCKAGE = RUBY_VERSION =~ /^1\.9\.1/
- GEM_PRELUDE_SUCKAGE = RUBY_VERSION =~ /^1\.9\.2/
@ferrous26
ferrous26 / example
Created November 1, 2011 16:51
Demonstrate possible problem with Range -> NSRange transformations
○ macirb
irb(main):001:0> framework 'Cocoa'
=> true
irb(main):002:0> a = (0..10).to_a
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):003:0> a.subarrayWithRange(0..10)
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
irb(main):004:0> a.slice(0..10)
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):005:0>
@ferrous26
ferrous26 / bench.rb
Created August 13, 2011 19:08
jiraSOAP 0.9 blog code snippets
require 'rubygems'
require 'jiraSOAP'
# I changed the URL and credentials as they are sensitive infos
$db = JIRA::JIRAService.new 'http://jira.domain.com:8080'
$db.login 'mark', 'password'
at_exit { $db.logout }
def bench_it issues, iterations
times = []
@ferrous26
ferrous26 / bench.rb
Created July 31, 2011 02:20
Simple #tap usage
require 'benchmark'
Benchmark.bmbm do |x|
x.report 'direct call' do
1_000_000.times do
x = true
x.nil?
@ferrous26
ferrous26 / bench.rb
Created July 5, 2011 05:11
preliminary benchmarks for json on MacRuby
require 'rubygems'
gem 'minitest', '>= 2.3.1'
require 'minitest/autorun'
require 'minitest/benchmark'
require 'json'
framework 'Foundation'
class Bench < MiniTest::Unit::TestCase
def self.order
:alpha
@ferrous26
ferrous26 / bench_method_to_proc.rb
Created June 18, 2011 17:02
Compare giving a block versus giving proc created using Method#to_proc
require 'rubygems'
gem 'minitest', '>= 2.2'
require 'minitest/autorun'
require 'minitest/benchmark'
class BenchMethodToProc < MiniTest::Unit::TestCase
def self.test_order
:alpha
end
@ferrous26
ferrous26 / compilation.markdown
Created May 26, 2011 05:09
Stdlib compilation times

2009 MBP (2.66 GHz C2D)

  • jobs=1 (7 minutes 32 seconds)

  • jobs=2 (4 minutes 31 seconds)

  • jobs=4 (4 minutes 20 seconds)

  • new (2 minutes 7 seconds)