Sha256: 6d1c778fe08de0b5e921837442d5d3d2d17165188f5562030dfa9137c58fc0e5

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

$LOAD_PATH.unshift('benchmark')
require 'bench'

require 'redis/connection/fakedis'
# Redis::Connection::Fakedis.start_recording
Redis::Connection::Fakedis.start_replay(:find)
Modis.redis_options = { driver: :fakedis }

class User
  include Modis::Model

  attribute :name, :string
  attribute :age, :integer
  attribute :percentage, :float
  attribute :created_at, :timestamp
  attribute :flag, :boolean
  attribute :array, :array
  attribute :hash, :hash
  attribute :string_or_hash, [:string, :hash]

  index :name
end

def create_user
  User.create!(name: 'Test', age: 30, percentage: 50.0, created_at: Time.now,
               flag: true, array: [1, 2, 3], hash: { k: :v }, string_or_hash: "an string")
end

user = create_user

n = 10_000

Bench.run do |b|
  b.report(:find) do
    n.times do
      User.find(user.id)
    end
  end

  b.report(:where) do
    n.times do
      User.where(name: user.name)
    end
  end
end

n = 1_000
i = 20
STDOUT.write "\n* Creating #{i} users for :where_multiple... "
STDOUT.flush
i.times { create_user }
puts "✔\n\n"

Bench.run do |b|
  b.report(:where_multiple) do
    n.times do
      User.where(name: 'Test')
    end
  end
end

# Redis::Connection::Fakedis.stop_recording(:find)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
modis-1.4.2 benchmark/find.rb
modis-1.4.1-java benchmark/find.rb
modis-1.4.1 benchmark/find.rb
modis-1.4.0 benchmark/find.rb