Sha256: e6e999cb42add65ce39c529cd73b10f8a2924fa614c5fc56b92e6ddee345cb84

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require_relative "helper"

Ohm.flush

class User < Ohm::Model
  attribute :fname
  attribute :lname
  attribute :bday
  attribute :gender
  attribute :city
  attribute :state
  attribute :country
  attribute :zip
end

create = lambda do |i|
  User.new(fname: "John#{i}",
           lname: "Doe#{i}",
           bday: Time.now.to_s,
           gender: "Male",
           city: "Los Angeles",
           state: "CA",
           country: "US",
           zip: "90210").save
end

10.times(&create)

require "benchmark"

t1 = Benchmark.realtime do
  User.all.sort_by(:fname, order: "DESC ALPHA").each do |user|
  end
end

t2 = Benchmark.realtime do
  ids = User.key[:all].smembers

  ids.each do |id|
    User[id]
  end
end

test "pipelined approach should be 1.5 at least times faster for 10 records" do
  assert(t2 / t1 >= 1.5)
end

90.times(&create)

t1 = Benchmark.realtime do
  User.all.sort_by(:fname, order: "DESC ALPHA").each do |user|
  end
end

t2 = Benchmark.realtime do
  ids = User.key[:all].smembers

  ids.each do |id|
    User[id]
  end
end

test "the pipelined approach should be 2 times faster for 100 records" do
  assert(t2 / t1 >= 2)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ohm-1.0.0.alpha1 test/pipeline-performance.rb