Skip to content

Instantly share code, notes, and snippets.

@actsasflinn
Forked from mattetti/gist:166821
Created August 13, 2009 04:03
Show Gist options
  • Save actsasflinn/166946 to your computer and use it in GitHub Desktop.
Save actsasflinn/166946 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'tokyo_tyrant'
TYRANT = TokyoTyrant::Table.new
AMOUNT_RECORDS = 8000
$TYRANT_ID = 0
RECORD = {
"component_version" => "X",
"state" => "Analyze",
"assignee" => "3002",
"snapshot_date" => "20080701",
"legacy_id" => "1318600",
"component_name" => "Something Core",
"priority" => "3"}
def bulk_of_docs
records = {}
AMOUNT_RECORDS.times do |n|
records[($TYRANT_ID += 1).to_s] = RECORD
end
records
end
runtime = 0.00
(1_000_000 / AMOUNT_RECORDS).times do |i|
records = bulk_of_docs
timer_start = Time.now
TYRANT.mput(records)
timer_end = Time.now
runtime += (timer_end - timer_start)
end
p "inserted 1_000_000 documents in #{runtime}"
# "inserted 1_000_000 documents in 33.104651"
TYRANT.clear
timer_start = Time.now
1_000_000.times do |i|
TYRANT[i] = RECORD
end
timer_end = Time.now
p "inserted 1_000_000 documents in #{timer_end - timer_start}"
# "inserted 1_000_000 documents in 170.204933"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment