Sha256: 3f653a2472692e395df192c9e480b537f534a8c1d1a80a2cfa653c39e8a0c5cd

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

require 'rubygems'
require 'benchmark'
require 'hashtree'
require 'securerandom'
require 'digest'

def gen_doc(i)
  name = "John Doe #{i}"
  email = "john.doe.#{i}@example.com"
  key = "jdoe#{i}"
  doc = { name: name, email: email, password: "secret#{i}" }
  return key, doc
end

Benchmark.bm do |x|
  puts "Creating a HashTree with 1.000 documents"
  x.report do
    @htree = HashTree.new
    1_000.times do |i|
      key, doc = gen_doc(i)
      @htree[key] = doc
    end
  end

  puts "Creating a HashTree with 10.000 documents"
  x.report do
    @htree = HashTree.new
    10_000.times do |i|
      key, doc = gen_doc(i)
      @htree[key] = doc
    end
  end

  puts "Creating a HashTree with 100.000 documents"
  x.report do
    @htree = HashTree.new
    100_000.times do |i|
      key, doc = gen_doc(i)
      @htree[key] = doc
    end
  end

  puts "Reading 1.000 random documents"
  x.report do
    1_000.times do |i|
      key = "jdoe#{rand(100_000)}"
      @htree[key]
    end
  end

  puts "Reading 10.000 random documents"
  x.report do
    10_000.times do |i|
      key = "jdoe#{rand(100_000)}"
      @htree[key]
    end
  end

  puts "Reading 100.000 random documents"
  x.report do
    100_000.times do |i|
      key = "jdoe#{rand(100_000)}"
      @htree[key]
    end
  end

  puts "Deleting 1.000 random documents"
  x.report do
    lhtree = @htree
    1_000.times do |i|
      key = "jdoe#{rand(100_000)}"
      lhtree.delete(key)
    end
  end

  puts "Deleting 10.000 random documents"
  x.report do
    lhtree = @htree
    10_000.times do |i|
      key = "jdoe#{rand(100_000)}"
      lhtree.delete(key)
    end
  end

  puts "Deleting 100.000 random documents"
  x.report do
    lhtree = @htree
    100_000.times do |i|
      key = "jdoe#{rand(100_000)}"
      lhtree.delete(key)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hashtree-0.0.2 examples/benchmarks.rb
hashtree-0.0.1 examples/benchmarks.rb