Skip to content

Instantly share code, notes, and snippets.

@der-flo
Created June 18, 2013 20:15
Show Gist options
  • Save der-flo/5808915 to your computer and use it in GitHub Desktop.
Save der-flo/5808915 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'aws-sdk'
require 'forwardable'
require 'futuroscope/convenience'
region = AWS.regions['eu-west-1']
table = region.dynamo_db.tables['futuroscope']
unless table.exists?
table = region.dynamo_db.tables.create('futuroscope', 10, 5,
hash_key: { id: :number })
sleep 1 while table.status == :creating
end
table.load_schema
table.items.each(&:delete)
1.upto(5) do |index|
table.items.create(id: index, value: index.to_s * 90)
end
puts 'starting loop'
3.times do
puts(Benchmark.realtime do
1.upto(5) do |index|
table.items[index].attributes[:value]
end
end)
puts(Benchmark.realtime do
(1..5).collect do |index|
future { table.items[index].attributes[:value] }
end.each do |value|
value.to_s
end
end)
puts '---'
sleep 1
end
# scp test.rb host:~ && ssh host AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY ruby test.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment