A
ara howard
this one's for you charlie ;-)
NAME
threadify.rb
SYNOPSIS
enumerable = %w( a b c d )
enumerable.threadify(2){ 'process this block using two worker
threads' }
DESCRIPTION
threadify.rb makes it stupid easy to process a bunch of data using
'n'
worker threads
INSTALL
gem install threadify
URI
http://rubyforge.org/projects/codeforpeople
SAMPLES
<========< sample/a.rb >========>
~ > cat sample/a.rb
require 'open-uri'
require 'yaml'
require 'rubygems'
require 'threadify'
uris =
%w(
http://google.com
http://yahoo.com
http://rubyforge.org
http://ruby-lang.org
http://kcrw.org
http://drawohara.com
http://codeforpeople.com
)
time 'without threadify' do
uris.each do |uri|
body = open(uri){|pipe| pipe.read}
end
end
time 'with threadify' do
uris.threadify do |uri|
body = open(uri){|pipe| pipe.read}
end
end
BEGIN {
def time label
a = Time.now.to_f
yield
ensure
b = Time.now.to_f
y label => (b - a)
end
}
~ > ruby sample/a.rb
---
without threadify: 7.41900205612183
---
with threadify: 3.69886112213135
a @ http://codeforpeople.com/
NAME
threadify.rb
SYNOPSIS
enumerable = %w( a b c d )
enumerable.threadify(2){ 'process this block using two worker
threads' }
DESCRIPTION
threadify.rb makes it stupid easy to process a bunch of data using
'n'
worker threads
INSTALL
gem install threadify
URI
http://rubyforge.org/projects/codeforpeople
SAMPLES
<========< sample/a.rb >========>
~ > cat sample/a.rb
require 'open-uri'
require 'yaml'
require 'rubygems'
require 'threadify'
uris =
%w(
http://google.com
http://yahoo.com
http://rubyforge.org
http://ruby-lang.org
http://kcrw.org
http://drawohara.com
http://codeforpeople.com
)
time 'without threadify' do
uris.each do |uri|
body = open(uri){|pipe| pipe.read}
end
end
time 'with threadify' do
uris.threadify do |uri|
body = open(uri){|pipe| pipe.read}
end
end
BEGIN {
def time label
a = Time.now.to_f
yield
ensure
b = Time.now.to_f
y label => (b - a)
end
}
~ > ruby sample/a.rb
---
without threadify: 7.41900205612183
---
with threadify: 3.69886112213135
a @ http://codeforpeople.com/