Skip to content

Instantly share code, notes, and snippets.

@phstc
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phstc/bdeab70f924e73800440 to your computer and use it in GitHub Desktop.
Save phstc/bdeab70f924e73800440 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/crowdmob/goamz/aws"
"github.com/crowdmob/goamz/dynamodb"
"log"
"os"
"time"
)
func main() {
start := time.Now()
fmt.Printf("starting\n")
os.Setenv("AWS_ACCESS_KEY_ID", "...")
os.Setenv("AWS_SECRET_ACCESS_KEY", "...")
auth, err := aws.EnvAuth()
if err != nil {
log.Fatal(err.Error())
}
ddbs := dynamodb.New(auth, aws.USEast)
primary := dynamodb.NewStringAttribute("account_id", "")
key := dynamodb.PrimaryKey{primary, nil}
table := ddbs.NewTable("moby_events", key)
q := dynamodb.NewQuery(table)
// q.AddKey(&dynamodb.Key{HashKey: "test"})
acs := []dynamodb.AttributeComparison{
*dynamodb.NewStringAttributeComparison("account_id", "EQ", "CUfKqynamDnZV9+d"),
}
q.AddKeyConditions(acs)
result, err := dynamodb.RunQuery(q, table)
if err != nil {
log.Fatal(err.Error())
}
for i, n := range result {
fmt.Printf("%2d: %s\n", i, n["created_at"].Value)
}
// fmt.Printf("%s\n", q.String())
elapsed := time.Since(start)
fmt.Printf("Completed in %dms", elapsed.Nanoseconds()/1000)
}
require 'aws-sdk'
started_at = Time.now
client = Aws::DynamoDB::Client.new(
region: 'us-east-1',
access_key_id: '...',
secret_access_key: '...'
)
resp = client.query(
table_name: 'moby_events',
key_conditions: {
'account_id' => {
attribute_value_list: ['CUfKqynamDnZV9+d'],
comparison_operator: 'EQ',
},
}
)
resp.items.each_with_index do |item, index|
puts "#{index}: #{item['created_at']}"
end
puts "Completed in: #{(Time.now - started_at) * 1000} ms"

Result

golang completed in 1164.213ms

ruby completed in 2431.504ms

all execution

golang:

  • real 0m1.228s
  • user 0m0.217s
  • sys 0m0.029s

ruby:

  • real 0m3.292s
  • user 0m1.614s
  • sys 0m0.135s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment