Sha256: bc461c4bc3134bc8fe15822231deb1e9a520f0b78396517ee8f27000cd33e00f

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

$: << File.expand_path("../../lib", __FILE__)

require 'database_cleaner'
require 'mongoid'
require 'mongoid-rspec'
require 'mongoid_token'
require 'benchmark'

Mongoid.configure do |config|
  config.master = Mongo::Connection.new.db("mongoid_token_benchmark")
end

DatabaseCleaner.strategy = :truncation

# start benchmarks

token_length = 2

class Link
  include Mongoid::Document
  include Mongoid::Token
  field :url
  token :length => 2, :contains => :alphanumeric
end

class NoTokenLink
  include Mongoid::Document
  field :url
end

def create_link(token = true)
  if token
    Link.create(:url => "http://involved.com.au")
  else
    NoTokenLink.create(:url => "http://involved.com.au")
  end
end

Link.destroy_all
Link.create_indexes
num_records = [1, 50, 100, 1000, 2000, 3000, 4000]
puts "-- Alphanumeric token of length #{token_length} (#{62**token_length} possible tokens)"
Benchmark.bm do |b|
  num_records.each do |qty|
    b.report("#{qty.to_s.rjust(5, " ")} records    "){ qty.times{ create_link(false) } }
    b.report("#{qty.to_s.rjust(5, " ")} records tok"){ qty.times{ create_link } }
    Link.destroy_all
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid_token-1.1.0 benchmarks/benchmark.rb
mongoid_token-1.0.0 benchmarks/benchmark.rb