-
-
Save eregon/e552bf55d42ce128a9d89f41d57b637f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
require 'sequel' | |
# if ARGV.last == 'plugin' | |
# class Sequel::Model | |
# plugin :accessed_columns | |
# plugin :active_model | |
# plugin :association_pks | |
# plugin :auto_validations | |
# plugin :columns_updated | |
# plugin :composition | |
# plugin :dirty | |
# plugin :forbid_lazy_load | |
# plugin :insert_conflict | |
# plugin :instance_filters | |
# plugin :instance_hooks | |
# plugin :json_serializer | |
# plugin :serialization | |
# plugin :serialization_modification_detection | |
# plugin :tactical_eager_loading | |
# plugin :update_primary_key | |
# plugin :validation_contexts | |
# end | |
# end | |
if ARGV.first == 'eager_initialize' | |
module Sequel::Model::ClassMethods | |
def call(values) | |
o = allocate | |
o.instance_variable_set(:@values, values) | |
o.instance_variable_set(:@new, nil) | |
o.instance_variable_set(:@modified, nil) | |
o.instance_variable_set(:@singleton_setter_added, nil) | |
o.instance_variable_set(:@errors, nil) | |
o.instance_variable_set(:@this, nil) | |
o.instance_variable_set(:@server, nil) | |
o.instance_variable_set(:@skip_validation_on_next_save, nil) | |
o.instance_variable_set(:@changed_columns, nil) | |
o | |
end | |
end | |
module Sequel::Model::Associations::ClassMethods | |
def call(values) | |
o = super | |
o.instance_variable_set(:@associations, nil) | |
o.instance_variable_set(:@set_associated_object_if_same, nil) | |
o | |
end | |
end | |
# if ARGV.last == 'plugin' | |
# module Sequel::Plugins | |
# module AccessedColumns | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@accessed_columns, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module ActiveModel | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@_to_partial_path, nil) | |
# o.instance_variable_set(:@destroyed, nil) | |
# o.instance_variable_set(:@rollback_checker, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module AssociationPks | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@_association_pks, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module AutoValidations | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@_skip_auto_validations, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module ColumnsUpdated | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@columns_updated, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module Composition | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@compositions, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module Dirty | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@initial_values, nil) | |
# o.instance_variable_set(:@missing_initial_values, nil) | |
# o.instance_variable_set(:@previous_changes, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module ForbidLazyLoad | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@forbid_lazy_load, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module InsertConflict | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@insert_conflict_opts, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module InstanceFilters | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@instance_filters, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module InstanceHooks | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@instance_hooks, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module JsonSerializer | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@json_serializer_opts, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module Serialization | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@deserialized_values, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module SerializationModificationDetection | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@original_deserialized_values, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module TacticalEagerLoading | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@retrieved_by, nil) | |
# o.instance_variable_set(:@retrieved_with, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module UpdatePrimaryKey | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@pk_hash, nil) | |
# o | |
# end | |
# end | |
# end | |
# | |
# module ValidationContexts | |
# module ClassMethods | |
# def call(values) | |
# o = super | |
# o.instance_variable_set(:@validation_context, nil) | |
# o | |
# end | |
# end | |
# end | |
# end | |
# end | |
end | |
DB = Sequel.connect(ENV["DATABASE_URL"] || 'sqlite:/') | |
DB.create_table!(:ts) { String :s } | |
class T < Sequel::Model; end | |
DB[:ts].import([:s], [[""]] * 1000) | |
Benchmark.ips do |x| | |
x.iterations = 5 | |
x.warmup = 5 | |
x.report("Retrieve 1000 rows") { T.all } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby -v | |
truffleruby 20.3.0-dev-9e307608, like ruby 2.6.6, GraalVM CE JVM [x86_64-linux] | |
$ ruby bench_sequel_ivar.rb regular noplugin | |
Warming up -------------------------------------- | |
Retrieve 1000 rows 1.000 i/100ms | |
Retrieve 1000 rows 36.000 i/100ms | |
Retrieve 1000 rows 38.000 i/100ms | |
Retrieve 1000 rows 48.000 i/100ms | |
Retrieve 1000 rows 48.000 i/100ms | |
Calculating ------------------------------------- | |
Retrieve 1000 rows 484.686 (±10.3%) i/s - 2.400k in 5.017796s | |
Retrieve 1000 rows 485.277 (± 9.7%) i/s - 2.400k in 5.001642s | |
Retrieve 1000 rows 487.223 (± 9.0%) i/s - 2.448k in 5.075775s | |
Retrieve 1000 rows 484.654 (± 9.7%) i/s - 2.400k in 5.007845s | |
Retrieve 1000 rows 484.507 (±10.3%) i/s - 2.400k in 5.020653s | |
$ ruby bench_sequel_ivar.rb eager_initialize noplugin | |
Warming up -------------------------------------- | |
Retrieve 1000 rows 1.000 i/100ms | |
Retrieve 1000 rows 24.000 i/100ms | |
Retrieve 1000 rows 38.000 i/100ms | |
Retrieve 1000 rows 44.000 i/100ms | |
Retrieve 1000 rows 43.000 i/100ms | |
Calculating ------------------------------------- | |
Retrieve 1000 rows 486.889 (± 9.0%) i/s - 2.408k in 4.997253s | |
Retrieve 1000 rows 478.872 (±10.2%) i/s - 2.365k in 5.000465s | |
Retrieve 1000 rows 462.874 (±11.7%) i/s - 2.322k in 5.095361s | |
Retrieve 1000 rows 482.134 (±10.6%) i/s - 2.408k in 5.065922s | |
Retrieve 1000 rows 484.478 (± 9.9%) i/s - 2.408k in 5.031180s | |
$ ruby bench_sequel_ivar.rb regular noplugin | |
Warming up -------------------------------------- | |
Retrieve 1000 rows 1.000 i/100ms | |
Retrieve 1000 rows 26.000 i/100ms | |
Retrieve 1000 rows 42.000 i/100ms | |
Retrieve 1000 rows 46.000 i/100ms | |
Retrieve 1000 rows 46.000 i/100ms | |
Calculating ------------------------------------- | |
Retrieve 1000 rows 483.879 (± 9.5%) i/s - 2.392k in 4.998927s | |
Retrieve 1000 rows 486.778 (± 8.4%) i/s - 2.438k in 5.051549s | |
Retrieve 1000 rows 482.516 (±10.4%) i/s - 2.392k in 5.025322s | |
Retrieve 1000 rows 483.580 (±10.1%) i/s - 2.392k in 5.008741s | |
Retrieve 1000 rows 485.566 (± 9.5%) i/s - 2.438k in 5.075149s | |
$ ruby bench_sequel_ivar.rb eager_initialize noplugin | |
Warming up -------------------------------------- | |
Retrieve 1000 rows 1.000 i/100ms | |
Retrieve 1000 rows 9.000 i/100ms | |
Retrieve 1000 rows 37.000 i/100ms | |
Retrieve 1000 rows 45.000 i/100ms | |
Retrieve 1000 rows 46.000 i/100ms | |
Calculating ------------------------------------- | |
Retrieve 1000 rows 480.240 (± 9.6%) i/s - 2.392k in 5.037832s | |
Retrieve 1000 rows 475.427 (± 9.0%) i/s - 2.392k in 5.079791s | |
Retrieve 1000 rows 494.262 (± 5.5%) i/s - 2.484k in 5.044289s | |
Retrieve 1000 rows 486.093 (± 9.5%) i/s - 2.438k in 5.072741s | |
Retrieve 1000 rows 499.295 (± 3.2%) i/s - 2.530k in 5.072990s | |
With frequency scaling disabled, iterations=10, default warmup: | |
$ ruby bench_sequel_ivar.rb regular noplugin | |
Warming up -------------------------------------- | |
Retrieve 1000 rows 1.000 i/100ms | |
Retrieve 1000 rows 2.000 i/100ms | |
Retrieve 1000 rows 5.000 i/100ms | |
Retrieve 1000 rows 18.000 i/100ms | |
Retrieve 1000 rows 32.000 i/100ms | |
Retrieve 1000 rows 40.000 i/100ms | |
Retrieve 1000 rows 42.000 i/100ms | |
Retrieve 1000 rows 37.000 i/100ms | |
Retrieve 1000 rows 43.000 i/100ms | |
Retrieve 1000 rows 43.000 i/100ms | |
Calculating ------------------------------------- | |
Retrieve 1000 rows 435.838 (± 2.1%) i/s - 2.193k in 5.033821s | |
Retrieve 1000 rows 432.016 (± 3.9%) i/s - 2.193k in 5.085208s | |
Retrieve 1000 rows 426.397 (± 7.3%) i/s - 2.150k in 5.074138s | |
Retrieve 1000 rows 431.443 (± 5.8%) i/s - 2.150k in 5.003244s | |
Retrieve 1000 rows 429.385 (± 6.3%) i/s - 2.150k in 5.031011s | |
Retrieve 1000 rows 434.342 (± 4.6%) i/s - 2.193k in 5.061207s | |
Retrieve 1000 rows 421.715 (± 9.0%) i/s - 2.107k in 5.046342s | |
Retrieve 1000 rows 433.625 (± 5.1%) i/s - 2.193k in 5.072863s | |
Retrieve 1000 rows 430.171 (± 6.0%) i/s - 2.193k in 5.119707s | |
Retrieve 1000 rows 424.770 (± 8.5%) i/s - 2.107k in 5.004734s | |
$ ruby bench_sequel_ivar.rb eager_initialize noplugin | |
Warming up -------------------------------------- | |
Retrieve 1000 rows 1.000 i/100ms | |
Retrieve 1000 rows 2.000 i/100ms | |
Retrieve 1000 rows 7.000 i/100ms | |
Retrieve 1000 rows 20.000 i/100ms | |
Retrieve 1000 rows 37.000 i/100ms | |
Retrieve 1000 rows 39.000 i/100ms | |
Retrieve 1000 rows 33.000 i/100ms | |
Retrieve 1000 rows 37.000 i/100ms | |
Retrieve 1000 rows 32.000 i/100ms | |
Retrieve 1000 rows 44.000 i/100ms | |
Calculating ------------------------------------- | |
Retrieve 1000 rows 429.286 (± 7.0%) i/s - 2.156k in 5.051781s | |
Retrieve 1000 rows 434.819 (± 3.0%) i/s - 2.200k in 5.064403s | |
Retrieve 1000 rows 429.039 (± 6.5%) i/s - 2.156k in 5.053074s | |
Retrieve 1000 rows 431.393 (± 5.6%) i/s - 2.156k in 5.016720s | |
Retrieve 1000 rows 416.398 (± 9.8%) i/s - 2.068k in 5.026738s | |
Retrieve 1000 rows 431.319 (± 4.4%) i/s - 2.156k in 5.009255s | |
Retrieve 1000 rows 431.097 (± 3.9%) i/s - 2.156k in 5.010084s | |
Retrieve 1000 rows 431.133 (± 4.9%) i/s - 2.156k in 5.016203s | |
Retrieve 1000 rows 429.550 (± 5.8%) i/s - 2.156k in 5.040850s | |
Retrieve 1000 rows 424.524 (± 7.8%) i/s - 2.112k in 5.012661s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment