Mam dostęp do różnych serwerów dla danych i próbowałem różnych metod w różnych klasach, używając podstawowego http: net, krawężnika, klienta-odpoczynku i open-uriWydajność Ruby/Rails: OpenURI vs NET: HTTP vs Curb vs Rest-Client
(1) Jak mierzyć wydajność w Ruby/Rails w ogóle? (2) Która metoda jest według ciebie szybsza?
Kod próbki ze wszystkich 4 różnymi sposobami:
url = "..."
begin
io_output = open(url, :http_basic_authentication => [@user_id, @user_password])
rescue => e
error = e.message #for debugging return this
return '-'
else
output = io_output.read
lub
require 'net/https'
uri = URI.parse("...")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
data = http.get(uri.request_uri) #http request status
res = Net::HTTP.get_response(uri)
puts res.body if res.is_a?(Net::HTTPSuccess)
lub
require 'curb'
url = "..."
c = Curl::Easy.new(url) do |curl|
curl.headers["Content-type"] = "application/json"
curl.headers["Authorization"] = "Token ..."
end
c.perform
puts c.body_str
lub
url = "..."
resource = RestClient::Resource.new(url,
:headers => { :Authorization => "Token ...",
:content_type => "application/json"})
begin
output = resource.get
rescue => e
error = e.message #for debugging return this
return '-'
else ...
end
Znalazłem http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html Spróbuję go. – nevermind
Opublikuj swoje wyniki jako odpowiedź. Byłbym ciekawy ich zobaczyć. –
Mam zamiar zrobić więcej testów, ale! uruchamiając to 5 razy dla każdego klienta: http :: net ~ 13 sekund open-uri ~ 8 sekund odpoczynku-client ~ 6.9 i krawężnik ~ 6.3 sekund – nevermind