Skip to content

Commit 23ef7cc

Browse files
sgonyeageemus
authored andcommitted
Added StreamlyFFI to the list of benchmark gems. Added a Benchmark.bmbm benchmark file. Fixed the tests path in the Rakefile.
1 parent 6d17cd9 commit 23ef7cc

File tree

3 files changed

+114
-3
lines changed

3 files changed

+114
-3
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ group :benchmark do
88
gem 'rest-client'
99
gem 'tach', '0.0.5'
1010
gem 'typhoeus'
11+
gem 'streamly_ffi'
1112
end

Rakefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ task :default => :test
4747

4848
require 'rake/testtask'
4949
Rake::TestTask.new(:test) do |test|
50-
test.libs << 'lib' << 'test'
51-
test.pattern = 'test/**/test_*.rb'
50+
test.libs << 'lib' << 'tests'
51+
test.pattern = 'tests/**/test_*.rb'
5252
test.verbose = true
5353
end
5454

5555
desc "Generate RCov test coverage and open in your browser"
5656
task :coverage do
5757
require 'rcov'
5858
sh "rm -fr coverage"
59-
sh "rcov test/test_*.rb"
59+
sh "rcov tests/test_*.rb"
6060
sh "open coverage/index.html"
6161
end
6262

benchmarks/vs_for_url.rb

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
require 'rubygems' if RUBY_VERSION < '1.9'
2+
require 'bundler'
3+
4+
Bundler.require(:default)
5+
Bundler.require(:benchmark)
6+
7+
require 'benchmark'
8+
require 'net/http'
9+
require 'open-uri'
10+
require 'uri'
11+
12+
url = ARGV[0] || "http://localhost:8080/" # nginx default
13+
uri = URI.parse(url)
14+
iters = (ARGV[1] || 1000).to_i
15+
16+
Benchmark.bmbm do |x|
17+
x.report('em-http-request') do
18+
iters.times do
19+
EventMachine.run {
20+
http = EventMachine::HttpRequest.new(url).get
21+
22+
http.callback {
23+
http.response
24+
EventMachine.stop
25+
}
26+
}
27+
end
28+
end
29+
30+
x.report('Excon') do
31+
iters.times do
32+
Excon.get(url).body
33+
end
34+
end
35+
36+
excon = Excon.new(url)
37+
x.report('Excon (persistent)') do
38+
iters.times do
39+
excon.request(:method => 'get').body
40+
end
41+
end
42+
43+
x.report('HTTParty') do
44+
iters.times do
45+
HTTParty.get(url).body
46+
end
47+
end
48+
49+
x.report('Net::HTTP') do
50+
# Net::HTTP.get('localhost', '/data/1000', 9292)
51+
iters.times do
52+
Net::HTTP.start(uri.host, uri.port) {|http| http.get('/data/1000').body }
53+
end
54+
end
55+
56+
Net::HTTP.start(uri.host, uri.port) do |http|
57+
x.report('Net::HTTP (persistent)') do
58+
iters.times do
59+
http.get('/data/1000').body
60+
end
61+
end
62+
end
63+
64+
x.report('open-uri') do
65+
iters.times do
66+
open(url).read
67+
end
68+
end
69+
70+
x.report('RestClient') do
71+
iters.times do
72+
RestClient.get(url)
73+
end
74+
end
75+
76+
x.report('Typhoeus') do
77+
iters.times do
78+
Typhoeus::Request.get(url).body
79+
end
80+
end
81+
82+
x.report('StreamlyFFI (Persistent)') do
83+
conn = StreamlyFFI::Connection.new
84+
iters.times do
85+
conn.get(url)
86+
end
87+
end
88+
end
89+
90+
# +------------------------+----------+
91+
# | tach | total |
92+
# +------------------------+----------+
93+
# | em-http-request | 3.828347 |
94+
# +------------------------+----------+
95+
# | Excon | 1.541997 |
96+
# +------------------------+----------+
97+
# | Excon (persistent) | 1.454728 |
98+
# +------------------------+----------+
99+
# | HTTParty | 2.551734 |
100+
# +------------------------+----------+
101+
# | Net::HTTP | 2.342450 |
102+
# +------------------------+----------+
103+
# | Net::HTTP (persistent) | 2.434209 |
104+
# +------------------------+----------+
105+
# | open-uri | 2.898245 |
106+
# +------------------------+----------+
107+
# | RestClient | 2.834506 |
108+
# +------------------------+----------+
109+
# | Typhoeus | 1.828265 |
110+
# +------------------------+----------+

0 commit comments

Comments
 (0)