Created
May 15, 2009 09:59
-
-
Save Sixeight/112153 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'net/http' | |
require 'open-uri' | |
require 'benchmark' | |
require 'rubygems' | |
require 'hpricot' | |
require 'typhoeus' | |
words = 50.times.map { ('a'..'z').to_a.shuffle.take(rand(4) + 1).join } | |
res1 = res2 = res3 = nil | |
puts 'Search words;' | |
p words | |
puts | |
def get_titles(q) | |
(Hpricot(open("http://www.google.com/search?q=#{q}").read)/'title').text | |
end | |
class Remote; include Typhoeus end | |
Benchmark.bmbm do |x| | |
x.report do | |
res1 = words.map {|q| get_titles(q) } | |
end | |
x.report do | |
res2 = words.map {|q| Thread.new { get_titles(q) } }.map(&:value) | |
end | |
x.report do | |
res3 = words.map {|q| | |
Remote.get("http://www.google.com/search?q=#{q}") | |
}.map {|res| | |
(Hpricot(res.body)/'title').text | |
} | |
end | |
end | |
p res1 == res2 && res1 == res3 && res2 == res3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment