Created
March 14, 2012 03:33
-
-
Save lcowell/2033824 to your computer and use it in GitHub Desktop.
em_inline_benchmark
This file contains hidden or 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
| require 'eventmachine' | |
| require 'em-synchrony' | |
| require "em-synchrony/em-http" | |
| require 'net/http' | |
| require 'benchmark' | |
| def em_http | |
| EM.synchrony do | |
| multi = EventMachine::Synchrony::Multi.new | |
| multi.add :page1, EventMachine::HttpRequest.new("http://localhost:3000/page1").aget | |
| multi.add :page2, EventMachine::HttpRequest.new("http://localhost:3000/page1").aget | |
| multi.add :page3, EventMachine::HttpRequest.new("http://localhost:3000/page1").aget | |
| multi.add :page4, EventMachine::HttpRequest.new("http://localhost:3000/page1").aget | |
| data = multi.perform.responses[:callback].values | |
| EventMachine.stop | |
| end | |
| end | |
| def inline_http | |
| (1..4).each do |n| | |
| uri = URI.parse("http://localhost:3000/page#{n}") | |
| Net::HTTP.get(uri) | |
| end | |
| end | |
| Benchmark.bmbm do |x| | |
| x.report("em") { em_http } | |
| x.report("inline") { inline_http } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment