title: Why is EventMachine's defer slower than a Ruby Thread?
body: <p>I have two scripts which use Mechanize to fetch a Google index page. I assumed EventMachine will be faster than a Ruby thread, but it's not.</p>
  
  <p>EventMachine code costs:  <code>"0.24s user 0.08s system 2% cpu 12.682 total"</code></p>
  
  <p>Ruby Thread code costs:  <code>"0.22s user 0.08s system 5% cpu 5.167 total "</code></p>
  
  <p>Am I using EventMachine in the wrong way? </p>
  
  <p>EventMachine:</p>
  
  <pre><code>require 'rubygems'
  require 'mechanize'
  require 'eventmachine'
  
  trap("INT") {EM.stop}
  
  EM.run do 
    num = 0
    operation = proc {
      agent = Mechanize.new
      sleep 1
      agent.get("http://google.com").body.to_s.size
    }
    callback = proc { |result|
      sleep 1
      puts result
      num+=1
      EM.stop if num == 9
    }
  
    10.times do 
      EventMachine.defer operation, callback
    end
  end
  </code></pre>
  
  <p>Ruby Thread:</p>
  
  <pre><code>require 'rubygems'
  require 'mechanize'
  
  
  threads = []
  10.times do 
    threads &lt;&lt; Thread.new do 
      agent = Mechanize.new
      sleep 1
      puts agent.get("http://google.com").body.to_s.size
      sleep 1
    end
  end
  
  
  threads.each do |aThread| 
    aThread.join
  end
  </code></pre>