Skip to content

Instantly share code, notes, and snippets.

@actsasbuffoon
Created August 17, 2010 23:45
Show Gist options
  • Save actsasbuffoon/532669 to your computer and use it in GitHub Desktop.
Save actsasbuffoon/532669 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongo'
def rand_string(ary, len = 16)
r = []
len.times {r << ary[rand ary.length]}
r.join("")
end
class PeriodicUpdater
attr_accessor :interval
def initialize(args = {})
args.each {|k, v| send("#{k}=", v)}
@last_update = Time.now
end
def check(subject)
diff = Time.now - @last_update
if diff > @interval
puts subject
@last_update = Time.now
end
end
end
pu = PeriodicUpdater.new(:interval => 5)
iterations = 10_000_000
db = Mongo::Connection.new("localhost").db("example_db")
coll = db.collection("example_collection")
chars = %w[q w e r t y u i o p a s d f g h j k l z x c v b n m Q W E R T Y U I O P A S D F G H J K L Z X C V B N M 1 2 3 4 5 6 7 8 9 0]
iterations.times do |i|
pu.check "#{i}/#{iterations}"
coll.insert({:foo => rand_string(chars, 1024), :bar => rand_string(chars, 1024),:baz => rand_string(chars, 1024)})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment