Sha256: 42d2ba230413d1e68c5000937ec3324a65c9bb002bc82752bb162b84cad3df98

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require "rom-factory"
require "rom-core"
require "active_record"
require "factory_bot"
require "fabrication"
require "benchmark/ips"

DATABASE_URL = "postgres://localhost/rom_factory_bench"

rom = ROM.container(:sql, DATABASE_URL) do |conf|
  conf.default.connection.create_table?(:users) do
    primary_key :id
    column :last_name, String, null: false
    column :first_name, String, null: false
    column :admin, TrueClass
  end

  conf.relation(:users) do
    schema(infer: true)
  end
end

factory = ROM::Factory.configure { |c| c.rom = rom }

factory.define(:user) do |f|
  f.first_name { "John" }
  f.last_name { "Doe" }
  f.admin { false }
end

class User < ActiveRecord::Base
end

ActiveRecord::Base.establish_connection(DATABASE_URL)

FactoryBot.define do
  factory(:user) do
    first_name { "John" }
    last_name  { "Doe" }
    admin { false }
  end
end

Fabricator(:user) do
  first_name { "John" }
  last_name  { "Doe" }
  admin { false }
end

Benchmark.ips do |x|
  x.report("rom-factory persisted struct") do
    factory[:user]
  end

  x.report("factory_bot") do
    FactoryBot.create(:user)
  end

  x.report("fabrication") do
    Fabricate(:user)
  end

  x.compare!
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom-factory-0.12.0 benchmarks/basic.rb
rom-factory-0.11.0 benchmarks/basic.rb