Skip to content

Instantly share code, notes, and snippets.

@kenpratt
Created December 7, 2012 23:07
Show Gist options
  • Save kenpratt/4237351 to your computer and use it in GitHub Desktop.
Save kenpratt/4237351 to your computer and use it in GitHub Desktop.
Script timing simple Dropbox operations
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), ".."))
$:.unshift File.join(ROOT_PATH, "vendor", "dropbox-ruby-sdk", "lib")
require "dropbox_sdk"
require "fileutils"
app_key = ENV["DROPBOX_APP_KEY"]
app_secret = ENV["DROPBOX_APP_SECRET"]
auth_key = ENV["DROPBOX_AUTH_KEY"]
auth_secret = ENV["DROPBOX_AUTH_SECRET"]
access_type = ENV["DROPBOX_ACCESS_TYPE"] || "dropbox" # "app_folder"
session = DropboxSession.new(app_key, app_secret)
session.set_access_token(auth_key, auth_secret)
client = DropboxClient.new(session, access_type)
def print_res(res, cstart)
cend = Time.now
str = case res
when Hash
"(data)"
else
res.inspect
end
puts "#{str} (#{((cend - cstart)*1000).round}ms)"
end
start = Time.now
cstart = Time.now
path = "/tmp/hello#{rand(1000)}"
print "Creating #{path}: "
cstart = Time.now
res = client.file_create_folder(path)
print_res(res, cstart)
print "Fetching metadata for #{path}: "
cstart = Time.now
res = client.metadata(path)
print_res(res, cstart)
f0path = "#{path}/tmp.rb"
print "Uploading #{f0path}: "
cstart = Time.now
File.open(__FILE__, "r") {|f| res = client.put_file(f0path, f); print_res(res, cstart) }
print "Fetching metadata for #{f0path}: "
cstart = Time.now
res = client.metadata(path)
print_res(res, cstart)
f1path = "#{path}/tmp.rb"
print "Uploading #{f1path}: "
cstart = Time.now
File.open(__FILE__, "r") {|f| res = client.put_file(f1path, f); print_res(res, cstart) }
print "Fetching metadata for #{f1path}: "
cstart = Time.now
res = client.metadata(path)
print_res(res, cstart)
f2path = "#{path}/tmp.rb"
print "Uploading #{f2path}: "
cstart = Time.now
File.open(__FILE__, "r") {|f| res = client.put_file(f2path, f); print_res(res, cstart) }
print "Fetching metadata for #{f2path}: "
cstart = Time.now
res = client.metadata(path)
print_res(res, cstart)
print "Fetching metadata for #{path}: "
cstart = Time.now
res = client.metadata(path)
print_res(res, cstart)
finish = Time.now
puts "Took #{((finish - start)*1000).round}ms"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment