excon 0.62.0 → 0.92.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +0 -1
  3. data/LICENSE.md +1 -1
  4. data/README.md +7 -6
  5. data/data/cacert.pem +1220 -1828
  6. data/excon.gemspec +19 -3
  7. data/lib/excon/connection.rb +216 -139
  8. data/lib/excon/constants.rb +38 -13
  9. data/lib/excon/error.rb +15 -0
  10. data/lib/excon/headers.rb +4 -3
  11. data/lib/excon/instrumentors/logging_instrumentor.rb +5 -16
  12. data/lib/excon/instrumentors/standard_instrumentor.rb +2 -9
  13. data/lib/excon/middlewares/base.rb +6 -0
  14. data/lib/excon/middlewares/capture_cookies.rb +1 -1
  15. data/lib/excon/middlewares/decompress.rb +11 -4
  16. data/lib/excon/middlewares/expects.rb +7 -1
  17. data/lib/excon/middlewares/idempotent.rb +20 -3
  18. data/lib/excon/middlewares/instrumentor.rb +8 -0
  19. data/lib/excon/middlewares/mock.rb +12 -3
  20. data/lib/excon/middlewares/redirect_follower.rb +25 -3
  21. data/lib/excon/middlewares/response_parser.rb +3 -0
  22. data/lib/excon/pretty_printer.rb +1 -8
  23. data/lib/excon/response.rb +12 -9
  24. data/lib/excon/socket.rb +59 -42
  25. data/lib/excon/ssl_socket.rb +37 -15
  26. data/lib/excon/test/plugin/server/exec.rb +5 -2
  27. data/lib/excon/test/plugin/server/puma.rb +4 -1
  28. data/lib/excon/test/plugin/server/unicorn.rb +5 -0
  29. data/lib/excon/test/plugin/server/webrick.rb +4 -1
  30. data/lib/excon/test/server.rb +1 -1
  31. data/lib/excon/unix_socket.rb +1 -0
  32. data/lib/excon/utils.rb +59 -5
  33. data/lib/excon/version.rb +1 -1
  34. data/lib/excon.rb +25 -17
  35. metadata +27 -98
  36. data/.document +0 -5
  37. data/.gitignore +0 -13
  38. data/.rspec +0 -3
  39. data/.travis.yml +0 -29
  40. data/Gemfile +0 -19
  41. data/Rakefile +0 -41
  42. data/benchmarks/class_vs_lambda.rb +0 -50
  43. data/benchmarks/concat_vs_insert.rb +0 -21
  44. data/benchmarks/concat_vs_interpolate.rb +0 -22
  45. data/benchmarks/cr_lf.rb +0 -21
  46. data/benchmarks/downcase-eq-eq_vs_casecmp.rb +0 -169
  47. data/benchmarks/excon.rb +0 -69
  48. data/benchmarks/excon_vs.rb +0 -165
  49. data/benchmarks/for_vs_array_each.rb +0 -27
  50. data/benchmarks/for_vs_hash_each.rb +0 -27
  51. data/benchmarks/has_key-vs-lookup.rb +0 -177
  52. data/benchmarks/headers_case_sensitivity.rb +0 -83
  53. data/benchmarks/headers_split_vs_match.rb +0 -34
  54. data/benchmarks/implicit_block-vs-explicit_block.rb +0 -98
  55. data/benchmarks/merging.rb +0 -21
  56. data/benchmarks/single_vs_double_quotes.rb +0 -21
  57. data/benchmarks/string_ranged_index.rb +0 -87
  58. data/benchmarks/strip_newline.rb +0 -115
  59. data/benchmarks/vs_stdlib.rb +0 -82
  60. data/changelog.txt +0 -1083
  61. data/spec/excon/error_spec.rb +0 -139
  62. data/spec/excon/test/server_spec.rb +0 -28
  63. data/spec/excon_spec.rb +0 -7
  64. data/spec/helpers/file_path_helpers.rb +0 -22
  65. data/spec/requests/basic_spec.rb +0 -40
  66. data/spec/requests/eof_requests_spec.rb +0 -36
  67. data/spec/requests/unix_socket_spec.rb +0 -46
  68. data/spec/spec_helper.rb +0 -24
  69. data/spec/support/shared_contexts/test_server_context.rb +0 -83
  70. data/spec/support/shared_examples/shared_example_for_clients.rb +0 -218
  71. data/spec/support/shared_examples/shared_example_for_streaming_clients.rb +0 -20
  72. data/spec/support/shared_examples/shared_example_for_test_servers.rb +0 -16
  73. data/tests/authorization_header_tests.rb +0 -29
  74. data/tests/bad_tests.rb +0 -47
  75. data/tests/basic_tests.rb +0 -351
  76. data/tests/batch_requests.rb +0 -133
  77. data/tests/complete_responses.rb +0 -31
  78. data/tests/data/127.0.0.1.cert.crt +0 -20
  79. data/tests/data/127.0.0.1.cert.key +0 -27
  80. data/tests/data/excon.cert.crt +0 -20
  81. data/tests/data/excon.cert.key +0 -27
  82. data/tests/data/xs +0 -1
  83. data/tests/error_tests.rb +0 -145
  84. data/tests/header_tests.rb +0 -119
  85. data/tests/middlewares/canned_response_tests.rb +0 -34
  86. data/tests/middlewares/capture_cookies_tests.rb +0 -34
  87. data/tests/middlewares/decompress_tests.rb +0 -157
  88. data/tests/middlewares/escape_path_tests.rb +0 -36
  89. data/tests/middlewares/idempotent_tests.rb +0 -206
  90. data/tests/middlewares/instrumentation_tests.rb +0 -315
  91. data/tests/middlewares/mock_tests.rb +0 -304
  92. data/tests/middlewares/redirect_follower_tests.rb +0 -112
  93. data/tests/pipeline_tests.rb +0 -40
  94. data/tests/proxy_tests.rb +0 -306
  95. data/tests/query_string_tests.rb +0 -87
  96. data/tests/rackups/basic.rb +0 -41
  97. data/tests/rackups/basic.ru +0 -3
  98. data/tests/rackups/basic_auth.ru +0 -14
  99. data/tests/rackups/deflater.ru +0 -4
  100. data/tests/rackups/proxy.ru +0 -18
  101. data/tests/rackups/query_string.ru +0 -13
  102. data/tests/rackups/redirecting.ru +0 -23
  103. data/tests/rackups/redirecting_with_cookie.ru +0 -40
  104. data/tests/rackups/request_headers.ru +0 -15
  105. data/tests/rackups/request_methods.ru +0 -21
  106. data/tests/rackups/response_header.ru +0 -18
  107. data/tests/rackups/ssl.ru +0 -16
  108. data/tests/rackups/ssl_mismatched_cn.ru +0 -15
  109. data/tests/rackups/ssl_verify_peer.ru +0 -16
  110. data/tests/rackups/streaming.ru +0 -30
  111. data/tests/rackups/thread_safety.ru +0 -17
  112. data/tests/rackups/timeout.ru +0 -14
  113. data/tests/rackups/webrick_patch.rb +0 -34
  114. data/tests/request_headers_tests.rb +0 -21
  115. data/tests/request_method_tests.rb +0 -47
  116. data/tests/request_tests.rb +0 -59
  117. data/tests/response_tests.rb +0 -197
  118. data/tests/servers/bad.rb +0 -20
  119. data/tests/servers/eof.rb +0 -17
  120. data/tests/servers/error.rb +0 -20
  121. data/tests/servers/good.rb +0 -350
  122. data/tests/test_helper.rb +0 -306
  123. data/tests/thread_safety_tests.rb +0 -39
  124. data/tests/timeout_tests.rb +0 -12
  125. data/tests/utils_tests.rb +0 -81
@@ -1,165 +0,0 @@
1
- require 'rubygems' if RUBY_VERSION < '1.9'
2
- require 'bundler'
3
-
4
- Bundler.require(:default)
5
- Bundler.require(:benchmark)
6
-
7
- require 'sinatra/base'
8
-
9
- require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'excon')
10
-
11
- module Excon
12
- class Server < Sinatra::Base
13
-
14
- def self.run
15
- Rack::Handler::WEBrick.run(
16
- Excon::Server.new,
17
- :Port => 9292,
18
- :AccessLog => [],
19
- :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR)
20
- )
21
- end
22
-
23
- get '/data/:amount' do |amount|
24
- 'x' * amount.to_i
25
- end
26
-
27
- end
28
- end
29
-
30
- def with_server(&block)
31
- pid = Process.fork do
32
- Excon::Server.run
33
- end
34
- loop do
35
- sleep(1)
36
- begin
37
- Excon.get('http://localhost:9292/api/foo')
38
- break
39
- rescue
40
- end
41
- end
42
- yield
43
- ensure
44
- Process.kill(9, pid)
45
- end
46
-
47
- require 'em-http-request'
48
- require 'httparty'
49
- require 'net/http'
50
- require 'open-uri'
51
- require 'rest_client'
52
- require 'tach'
53
- require 'typhoeus'
54
-
55
- size = 10_000
56
- path = '/data/' << size.to_s
57
- url = 'http://localhost:9292' << path
58
-
59
- times = 1_000
60
-
61
- with_server do
62
-
63
- Tach.meter(times) do
64
-
65
- tach('curb (persistent)') do |n|
66
- curb = Curl::Easy.new
67
-
68
- n.times do
69
- curb.url = url
70
- curb.http_get
71
- curb.body_str
72
- end
73
- end
74
-
75
- tach('em-http-request') do |n|
76
- EventMachine.run {
77
- count = 0
78
-
79
- n.times do
80
- http = EventMachine::HttpRequest.new(url).get
81
-
82
- http.callback {
83
- http.response
84
- count += 1
85
- EM.stop if count == n
86
- }
87
-
88
- http.errback {
89
- http.response
90
- count += 1
91
- EM.stop if count == n
92
- }
93
- end
94
- }
95
- end
96
-
97
- tach('Excon') do
98
- Excon.get(url).body
99
- end
100
-
101
- excon = Excon.new(url)
102
- tach('Excon (persistent)') do
103
- excon.request(:method => 'get').body
104
- end
105
-
106
- tach('HTTParty') do
107
- HTTParty.get(url).body
108
- end
109
-
110
- tach('Net::HTTP') do
111
- # Net::HTTP.get('localhost', path, 9292)
112
- Net::HTTP.start('localhost', 9292) {|http| http.get(path).body }
113
- end
114
-
115
- Net::HTTP.start('localhost', 9292) do |http|
116
- tach('Net::HTTP (persistent)') do
117
- http.get(path).body
118
- end
119
- end
120
-
121
- tach('open-uri') do
122
- open(url).read
123
- end
124
-
125
- tach('RestClient') do
126
- RestClient.get(url)
127
- end
128
-
129
- streamly = StreamlyFFI::Connection.new
130
- tach('StreamlyFFI (persistent)') do
131
- streamly.get(url)
132
- end
133
-
134
- tach('Typhoeus') do
135
- Typhoeus::Request.get(url).body
136
- end
137
-
138
- end
139
- end
140
-
141
- # +--------------------------+----------+
142
- # | tach | total |
143
- # +--------------------------+----------+
144
- # | Excon (persistent) | 1.529095 |
145
- # +--------------------------+----------+
146
- # | curb (persistent) | 1.740387 |
147
- # +--------------------------+----------+
148
- # | Typhoeus | 1.876236 |
149
- # +--------------------------+----------+
150
- # | Excon | 2.001858 |
151
- # +--------------------------+----------+
152
- # | StreamlyFFI (persistent) | 2.200701 |
153
- # +--------------------------+----------+
154
- # | Net::HTTP | 2.395704 |
155
- # +--------------------------+----------+
156
- # | Net::HTTP (persistent) | 2.418099 |
157
- # +--------------------------+----------+
158
- # | HTTParty | 2.659317 |
159
- # +--------------------------+----------+
160
- # | RestClient | 2.958159 |
161
- # +--------------------------+----------+
162
- # | open-uri | 2.987051 |
163
- # +--------------------------+----------+
164
- # | em-http-request | 4.123798 |
165
- # +--------------------------+----------+
@@ -1,27 +0,0 @@
1
- require 'rubygems'
2
- require 'tach'
3
-
4
- data = ["some", "var", "goes", "in", :here, 0]
5
- Tach.meter(1_000_000) do
6
- tach('for') do
7
- for element in data
8
- element == nil
9
- end
10
- end
11
- tach('each') do
12
- data.each do |element|
13
- element == nil
14
- end
15
- end
16
- end
17
-
18
- # ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
19
- #
20
- # +------+----------+
21
- # | tach | total |
22
- # +------+----------+
23
- # | for | 2.958672 |
24
- # +------+----------+
25
- # | each | 2.983550 |
26
- # +------+----------+
27
- #
@@ -1,27 +0,0 @@
1
- require 'rubygems'
2
- require 'tach'
3
-
4
- data = {"some" => "var", "goes" => "in", :here => 0}
5
- Tach.meter(1_000_000) do
6
- tach('for') do
7
- for key, values in data
8
- key == values
9
- end
10
- end
11
- tach('each') do
12
- data.each do |key, values|
13
- key == values
14
- end
15
- end
16
- end
17
-
18
- # ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
19
- #
20
- # +------+----------+
21
- # | tach | total |
22
- # +------+----------+
23
- # | each | 2.748909 |
24
- # +------+----------+
25
- # | for | 2.949512 |
26
- # +------+----------+
27
- #
@@ -1,177 +0,0 @@
1
- # Copied from my benchmark_hell repo: github.com/sgonyea/benchmark_hell
2
-
3
- require 'benchmark'
4
-
5
- iters = 1000000
6
- hash = {
7
- 'some_key' => 'some_val',
8
- 'nil_key' => nil
9
- }
10
-
11
- puts 'Hash#has_key vs. Hash#[]'
12
- Benchmark.bmbm do |x|
13
- x.report('Hash#has_key') do
14
- iters.times.each do
15
- hash.has_key? 'some_key'
16
- end
17
- end
18
-
19
- x.report('Hash#has_key (if statement)') do
20
- iters.times.each do
21
- if hash.has_key?('other_key')
22
- "hooray!"
23
- end
24
- end
25
- end
26
-
27
- x.report('Hash#has_key (non-existant)') do
28
- iters.times.each do
29
- hash.has_key? 'other_key'
30
- end
31
- end
32
-
33
- x.report('Hash#[]') do
34
- iters.times.each do
35
- hash['some_key']
36
- end
37
- end
38
-
39
- x.report('Hash#[] (if statement)') do
40
- iters.times.each do
41
- if hash['some_key']
42
- "hooray!"
43
- end
44
- end
45
- end
46
-
47
- x.report('Hash#[] (non-existant)') do
48
- iters.times.each do
49
- hash['other_key']
50
- end
51
- end
52
-
53
- x.report('Hash#has_key (if statement) explicit nil check') do
54
- iters.times.each do
55
- if hash.has_key?('nil_key') && !hash['nil_key'].nil?
56
- "hooray!"
57
- end
58
- end
59
- end
60
-
61
-
62
- x.report('Hash#has_key (if statement) implicit nil check') do
63
- iters.times.each do
64
- if hash.has_key?('nil_key') && hash['nil_key']
65
- "hooray!"
66
- end
67
- end
68
- end
69
-
70
- x.report('Hash#[] (if statement with nil)') do
71
- iters.times.each do
72
- if hash['nil_key']
73
- "hooray!"
74
- end
75
- end
76
- end
77
- end
78
-
79
- =begin
80
-
81
- $ rvm exec bash -c 'echo $RUBY_VERSION && ruby has_key-vs-hash\[key\].rb'
82
-
83
- jruby-1.5.6
84
- Hash#has_key vs. Hash#[]
85
- Rehearsal ---------------------------------------------------------------
86
- Hash#has_key 0.410000 0.000000 0.410000 ( 0.341000)
87
- Hash#has_key (if statement) 0.145000 0.000000 0.145000 ( 0.145000)
88
- Hash#has_key (non-existant) 0.116000 0.000000 0.116000 ( 0.116000)
89
- Hash#[] 0.189000 0.000000 0.189000 ( 0.189000)
90
- Hash#[] (if statement) 0.176000 0.000000 0.176000 ( 0.176000)
91
- Hash#[] (non-existant) 0.302000 0.000000 0.302000 ( 0.302000)
92
- ------------------------------------------------------ total: 1.338000sec
93
-
94
- user system total real
95
- Hash#has_key 0.128000 0.000000 0.128000 ( 0.128000)
96
- Hash#has_key (if statement) 0.128000 0.000000 0.128000 ( 0.128000)
97
- Hash#has_key (non-existant) 0.153000 0.000000 0.153000 ( 0.153000)
98
- Hash#[] 0.206000 0.000000 0.206000 ( 0.206000)
99
- Hash#[] (if statement) 0.182000 0.000000 0.182000 ( 0.182000)
100
- Hash#[] (non-existant) 0.252000 0.000000 0.252000 ( 0.252000)
101
-
102
- macruby-0.7.1
103
- Hash#has_key vs. Hash#[]
104
- Rehearsal ---------------------------------------------------------------
105
- Hash#has_key 2.530000 0.050000 2.580000 ( 1.917643)
106
- Hash#has_key (if statement) 2.590000 0.050000 2.640000 ( 1.935221)
107
- Hash#has_key (non-existant) 2.580000 0.050000 2.630000 ( 1.964230)
108
- Hash#[] 2.240000 0.040000 2.280000 ( 1.640999)
109
- Hash#[] (if statement) 3.620000 0.070000 3.690000 ( 2.530248)
110
- Hash#[] (non-existant) 2.060000 0.040000 2.100000 ( 1.473487)
111
- ----------------------------------------------------- total: 15.920000sec
112
-
113
- user system total real
114
- Hash#has_key 2.230000 0.030000 2.260000 ( 1.661843)
115
- Hash#has_key (if statement) 2.180000 0.040000 2.220000 ( 1.605644)
116
- Hash#has_key (non-existant) 2.160000 0.040000 2.200000 ( 1.582561)
117
- Hash#[] 2.160000 0.030000 2.190000 ( 1.581448)
118
- Hash#[] (if statement) 3.440000 0.070000 3.510000 ( 2.393421)
119
- Hash#[] (non-existant) 2.330000 0.040000 2.370000 ( 1.699338)
120
-
121
- rbx-head
122
- Hash#has_key vs. Hash#[]
123
- Rehearsal ---------------------------------------------------------------
124
- Hash#has_key 0.660584 0.004932 0.665516 ( 0.508601)
125
- Hash#has_key (if statement) 0.261708 0.000532 0.262240 ( 0.263021)
126
- Hash#has_key (non-existant) 0.265908 0.000827 0.266735 ( 0.259509)
127
- Hash#[] 0.396607 0.001189 0.397796 ( 0.372997)
128
- Hash#[] (if statement) 0.553003 0.001589 0.554592 ( 0.543859)
129
- Hash#[] (non-existant) 0.323748 0.000884 0.324632 ( 0.319055)
130
- ------------------------------------------------------ total: 2.471511sec
131
-
132
- user system total real
133
- Hash#has_key 0.332239 0.000819 0.333058 ( 0.333809)
134
- Hash#has_key (if statement) 0.284344 0.000521 0.284865 ( 0.285330)
135
- Hash#has_key (non-existant) 0.339695 0.001301 0.340996 ( 0.324259)
136
- Hash#[] 0.298555 0.000368 0.298923 ( 0.299557)
137
- Hash#[] (if statement) 0.392755 0.000773 0.393528 ( 0.395473)
138
- Hash#[] (non-existant) 0.277721 0.000464 0.278185 ( 0.278540)
139
-
140
- ruby-1.8.7-p330
141
- Hash#has_key vs. Hash#[]
142
- Rehearsal ---------------------------------------------------------------
143
- Hash#has_key 0.450000 0.000000 0.450000 ( 0.450143)
144
- Hash#has_key (if statement) 0.440000 0.000000 0.440000 ( 0.448278)
145
- Hash#has_key (non-existant) 0.420000 0.000000 0.420000 ( 0.416959)
146
- Hash#[] 0.450000 0.000000 0.450000 ( 0.450727)
147
- Hash#[] (if statement) 0.550000 0.000000 0.550000 ( 0.555043)
148
- Hash#[] (non-existant) 0.530000 0.000000 0.530000 ( 0.527189)
149
- ------------------------------------------------------ total: 2.840000sec
150
-
151
- user system total real
152
- Hash#has_key 0.440000 0.000000 0.440000 ( 0.447746)
153
- Hash#has_key (if statement) 0.450000 0.000000 0.450000 ( 0.450331)
154
- Hash#has_key (non-existant) 0.420000 0.000000 0.420000 ( 0.419157)
155
- Hash#[] 0.450000 0.000000 0.450000 ( 0.454438)
156
- Hash#[] (if statement) 0.570000 0.000000 0.570000 ( 0.563948)
157
- Hash#[] (non-existant) 0.520000 0.000000 0.520000 ( 0.527866)
158
-
159
- ruby-1.9.2-p136
160
- Hash#has_key vs. Hash#[]
161
- Rehearsal ---------------------------------------------------------------
162
- Hash#has_key 0.690000 0.000000 0.690000 ( 0.691657)
163
- Hash#has_key (if statement) 0.630000 0.000000 0.630000 ( 0.638418)
164
- Hash#has_key (non-existant) 0.640000 0.000000 0.640000 ( 0.637510)
165
- Hash#[] 0.580000 0.000000 0.580000 ( 0.584500)
166
- Hash#[] (if statement) 0.840000 0.010000 0.850000 ( 0.837541)
167
- Hash#[] (non-existant) 0.810000 0.000000 0.810000 ( 0.811598)
168
- ------------------------------------------------------ total: 4.200000sec
169
-
170
- user system total real
171
- Hash#has_key 0.690000 0.000000 0.690000 ( 0.694192)
172
- Hash#has_key (if statement) 0.640000 0.000000 0.640000 ( 0.641729)
173
- Hash#has_key (non-existant) 0.630000 0.000000 0.630000 ( 0.634470)
174
- Hash#[] 0.580000 0.000000 0.580000 ( 0.587844)
175
- Hash#[] (if statement) 0.830000 0.000000 0.830000 ( 0.832323)
176
- Hash#[] (non-existant) 0.790000 0.010000 0.800000 ( 0.791689)
177
- =end
@@ -1,83 +0,0 @@
1
- require 'rubygems'
2
- require 'stringio'
3
- require 'tach'
4
-
5
- def all_match_socket
6
- io = StringIO.new
7
- io << "Connection: close\n"
8
- io << "Content-Length: 000\n"
9
- io << "Content-Type: text/html\n"
10
- io << "Date: Xxx, 00 Xxx 0000 00:00:00 GMT\n"
11
- io << "Server: xxx\n"
12
- io << "Transfer-Encoding: chunked\n"
13
- io << "\n\n"
14
- io.rewind
15
- io
16
- end
17
-
18
- Formatador.display_line('all_match')
19
- Formatador.indent do
20
- Tach.meter(10_000) do
21
- tach('compare on read') do
22
- socket, headers = all_match_socket, {}
23
- until ((data = socket.readline).chop!).empty?
24
- key, value = data.split(': ')
25
- headers[key] = value
26
- (key.casecmp('Transfer-Encoding') == 0) && (value.casecmp('chunked') == 0)
27
- (key.casecmp('Connection') == 0) && (value.casecmp('close') == 0)
28
- (key.casecmp('Content-Length') == 0)
29
- end
30
- end
31
-
32
- tach('original') do
33
- socket, headers = all_match_socket, {}
34
- until ((data = socket.readline).chop!).empty?
35
- key, value = data.split(': ')
36
- headers[key] = value
37
- end
38
- headers.has_key?('Transfer-Encoding') && headers['Transfer-Encoding'].casecmp('chunked') == 0
39
- headers.has_key?('Connection') && headers['Connection'].casecmp('close') == 0
40
- headers.has_key?('Content-Length')
41
- end
42
- end
43
- end
44
-
45
- def none_match_socket
46
- io = StringIO.new
47
- io << "Cache-Control: max-age=0\n"
48
- io << "Content-Type: text/html\n"
49
- io << "Date: Xxx, 00 Xxx 0000 00:00:00 GMT\n"
50
- io << "Expires: Xxx, 00 Xxx 0000 00:00:00 GMT\n"
51
- io << "Last-Modified: Xxx, 00 Xxx 0000 00:00:00 GMT\n"
52
- io << "Server: xxx\n"
53
- io << "\n\n"
54
- io.rewind
55
- io
56
- end
57
-
58
- Formatador.display_line('none_match')
59
- Formatador.indent do
60
- Tach.meter(10_000) do
61
- tach('compare on read') do
62
- socket, headers = none_match_socket, {}
63
- until ((data = socket.readline).chop!).empty?
64
- key, value = data.split(': ')
65
- headers[key] = value
66
- (key.casecmp('Transfer-Encoding') == 0) && (value.casecmp('chunked') == 0)
67
- (key.casecmp('Connection') == 0) && (value.casecmp('close') == 0)
68
- (key.casecmp('Content-Length') == 0)
69
- end
70
- end
71
-
72
- tach('original') do
73
- socket, headers = none_match_socket, {}
74
- until ((data = socket.readline).chop!).empty?
75
- key, value = data.split(': ')
76
- headers[key] = value
77
- end
78
- headers.has_key?('Transfer-Encoding') && headers['Transfer-Encoding'].casecmp('chunked') == 0
79
- headers.has_key?('Connection') && headers['Connection'].casecmp('close') == 0
80
- headers.has_key?('Content-Length')
81
- end
82
- end
83
- end
@@ -1,34 +0,0 @@
1
- require 'rubygems'
2
- require 'tach'
3
-
4
- data = "Content-Length: 100"
5
- Tach.meter(1_000_000) do
6
- tach('regex') do
7
- data.match(/(.*):\s(.*)/)
8
- header = [$1, $2]
9
- end
10
- tach('split') do
11
- header = data.split(': ', 2)
12
- end
13
- tach('split regex') do
14
- header = data.split(/:\s*/, 2)
15
- end
16
- end
17
-
18
- # +-------------+----------+
19
- # | tach | total |
20
- # +-------------+----------+
21
- # | split regex | 5.940233 |
22
- # +-------------+----------+
23
- # | split | 7.327549 |
24
- # +-------------+----------+
25
- # | regex | 8.736390 |
26
- # +-------------+----------+
27
-
28
- # +-------+----------+----------+
29
- # | tach | average | total |
30
- # +-------+----------+----------+
31
- # | regex | 4.680451 | 4.680451 |
32
- # +-------+----------+----------+
33
- # | split | 4.393218 | 4.393218 |
34
- # +-------+----------+----------+
@@ -1,98 +0,0 @@
1
- # Copied from my benchmark_hell repo: github.com/sgonyea/benchmark_hell
2
-
3
- require 'benchmark'
4
-
5
- iters = 1000000
6
-
7
- def do_explicit(&block)
8
- var = "hello"
9
- block.call(var)
10
- end
11
-
12
- def do_implicit
13
- var = "hello"
14
- yield(var)
15
- end
16
-
17
- puts 'explicit block vs implicit'
18
- Benchmark.bmbm do |x|
19
- x.report('explicit') do
20
- iters.times.each do
21
- do_explicit {|var|
22
- var << "goodbye"
23
- }
24
- end
25
- end
26
-
27
- x.report('implicit') do
28
- iters.times.each do
29
- do_implicit {|var|
30
- var << "goodbye"
31
- }
32
- end
33
- end
34
- end
35
-
36
- =begin
37
- rvm exec bash -c 'echo && echo $RUBY_VERSION && echo && ruby implicit_block-vs-explicit_block.rb'
38
-
39
- jruby-1.5.6
40
-
41
- explicit block vs implicit
42
- Rehearsal --------------------------------------------
43
- explicit 1.163000 0.000000 1.163000 ( 1.106000)
44
- implicit 0.499000 0.000000 0.499000 ( 0.499000)
45
- ----------------------------------- total: 1.662000sec
46
-
47
- user system total real
48
- explicit 0.730000 0.000000 0.730000 ( 0.730000)
49
- implicit 0.453000 0.000000 0.453000 ( 0.453000)
50
-
51
- macruby-0.7.1
52
-
53
- explicit block vs implicit
54
- Rehearsal --------------------------------------------
55
- explicit 5.070000 0.130000 5.200000 ( 3.546388)
56
- implicit 3.140000 0.050000 3.190000 ( 2.255986)
57
- ----------------------------------- total: 8.390000sec
58
-
59
- user system total real
60
- explicit 5.340000 0.140000 5.480000 ( 3.774963)
61
- implicit 3.170000 0.060000 3.230000 ( 2.279951)
62
-
63
- rbx-head
64
-
65
- explicit block vs implicit
66
- Rehearsal --------------------------------------------
67
- explicit 1.270136 0.006507 1.276643 ( 1.181588)
68
- implicit 0.839831 0.002203 0.842034 ( 0.820849)
69
- ----------------------------------- total: 2.118677sec
70
-
71
- user system total real
72
- explicit 0.960593 0.001526 0.962119 ( 0.966404)
73
- implicit 0.700361 0.001126 0.701487 ( 0.703591)
74
-
75
- ruby-1.8.7-p330
76
-
77
- explicit block vs implicit
78
- Rehearsal --------------------------------------------
79
- explicit 3.970000 0.000000 3.970000 ( 3.985157)
80
- implicit 1.560000 0.000000 1.560000 ( 1.567599)
81
- ----------------------------------- total: 5.530000sec
82
-
83
- user system total real
84
- explicit 3.990000 0.010000 4.000000 ( 4.002637)
85
- implicit 1.560000 0.000000 1.560000 ( 1.560901)
86
-
87
- ruby-1.9.2-p136
88
-
89
- explicit block vs implicit
90
- Rehearsal --------------------------------------------
91
- explicit 2.620000 0.010000 2.630000 ( 2.633762)
92
- implicit 1.080000 0.000000 1.080000 ( 1.076809)
93
- ----------------------------------- total: 3.710000sec
94
-
95
- user system total real
96
- explicit 2.630000 0.010000 2.640000 ( 2.637658)
97
- implicit 1.070000 0.000000 1.070000 ( 1.073589)
98
- =end
@@ -1,21 +0,0 @@
1
- require 'rubygems'
2
- require 'tach'
3
-
4
- Tach.meter(10_000) do
5
-
6
- tach('merge') do
7
- default = { :a => 1, :b => 2 }
8
- override = { :b => 3, :c => 4 }
9
- override = default.merge(override)
10
- end
11
-
12
- tach('loop') do
13
- default = { :a => 1, :b => 2 }
14
- override = { :b => 3, :c => 4 }
15
- for key, value in default
16
- override[key] ||= default[key]
17
- end
18
- override
19
- end
20
-
21
- end
@@ -1,21 +0,0 @@
1
- require 'rubygems'
2
- require 'tach'
3
-
4
- Tach.meter(1_000_000) do
5
- tach('double') do
6
- "path"
7
- end
8
- tach('single') do
9
- 'path'
10
- end
11
- end
12
-
13
- # [double, single]
14
- #
15
- # +--------+----------+
16
- # | tach | total |
17
- # +--------+----------+
18
- # | single | 0.416340 |
19
- # +--------+----------+
20
- # | double | 0.416570 |
21
- # +--------+----------+