1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

setting groundwork for benchs/optimization

This commit is contained in:
Wesley Beary 2009-06-23 00:04:29 -07:00
parent 7735d7797c
commit 7cd3f1a2ff
3 changed files with 29 additions and 13 deletions

View file

@ -2,7 +2,7 @@ require 'rubygems'
require 'benchwarmer'
require 'right_aws'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'fog/aws'
data = File.open(File.expand_path('~/.s3conf/s3config.yml')).read
@ -17,7 +17,7 @@ raws = RightAws::S3Interface.new(
)
raws.logger.level = 3 # ERROR
TIMES = 10
TIMES = 100
Benchmark.bm(25) do |bench|
bench.report('fog.put_bucket') do
@ -31,13 +31,13 @@ Benchmark.bm(25) do |bench|
bench.report('fog.put_object') do
TIMES.times do |x|
file = File.open(File.dirname(__FILE__) + '/spec/lorem.txt', 'r')
file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
fog.put_object('fogbench', "lorem_#{x}", file)
end
end
bench.report('raws.put') do
TIMES.times do |x|
file = File.open(File.dirname(__FILE__) + '/spec/lorem.txt', 'r')
file = File.open(File.dirname(__FILE__) + '/../spec/lorem.txt', 'r')
raws.put('rawsbench', "lorem_#{x}", file)
end
end
@ -63,4 +63,4 @@ Benchmark.bm(25) do |bench|
bench.report('raws.delete_bucket') do
raws.delete_bucket('rawsbench')
end
end
end

View file

@ -0,0 +1,19 @@
require 'rubygems'
require 'benchwarmer'
COUNT = 1000
data = "Content-Length: 100"
Benchmark.bmbm(25) do |bench|
bench.report('regex') do
COUNT.times do
header = data.match(/(.*):\s(.*)/)
"#{header[1]}: #{header[2]}"
end
end
bench.report('split') do
COUNT.times do
header = data.split(': ')
"#{header[0]}: #{header[1]}"
end
end
end

View file

@ -23,9 +23,6 @@ module Fog
end
def request(params)
params = {
:headers => {}
}.merge(params)
uri = URI.parse(params[:url])
path = "#{uri.path}"
if uri.query
@ -38,6 +35,7 @@ module Fog
end
request = "#{params[:method]} #{path} HTTP/1.1\r\n"
params[:headers] ||= {}
params[:headers]['Host'] = uri.host
if params[:body]
params[:headers]['Content-Length'] = params[:body].length
@ -51,13 +49,12 @@ module Fog
response = AWS::Response.new
response.status = @connection.readline[9..11].to_i
while true
data = @connection.readline
if data == "\r\n"
data = @connection.readline[0..-3]
if data == ""
break
end
if header = data.match(/(.*):\s(.*)\r\n/)
response.headers[header[1]] = header[2]
end
header = data.split(': ')
response.headers[header[0]] = header[1]
end
if response.headers['Content-Length']
content_length = response.headers['Content-Length'].to_i