Sha256: da82a9973f0e5a9f185536ab7054cc2db121f57b82e16b8f963379c5b8a1c1f8
Contents?: true
Size: 1.23 KB
Versions: 13
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true $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, %i[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
13 entries across 13 versions & 1 rubygems