diff --git a/benchmarks.yml b/benchmarks.yml index b02d76e7..3bdc10e2 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -26,6 +26,9 @@ railsbench: ruby-lsp: desc: Run several operations with the Ruby language server used by VSCode category: headline +sequel: + desc: sequel repeatedly queries entries in a SQLite table with highly-random names. + category: headline # # Other Benchmarks diff --git a/benchmarks/sequel/Gemfile b/benchmarks/sequel/Gemfile new file mode 100644 index 00000000..890fe4a4 --- /dev/null +++ b/benchmarks/sequel/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" +gem "sequel", "~> 5.63" +gem "sqlite3", "~> 1.4", platform: :ruby diff --git a/benchmarks/sequel/Gemfile.lock b/benchmarks/sequel/Gemfile.lock new file mode 100644 index 00000000..6fa186ad --- /dev/null +++ b/benchmarks/sequel/Gemfile.lock @@ -0,0 +1,17 @@ +GEM + remote: https://rubygems.org/ + specs: + mini_portile2 (2.8.1) + sequel (5.64.0) + sqlite3 (1.5.4) + mini_portile2 (~> 2.8.0) + +PLATFORMS + x86_64-darwin-20 + +DEPENDENCIES + sequel (~> 5.63) + sqlite3 (~> 1.4) + +BUNDLED WITH + 2.4.1 diff --git a/benchmarks/sequel/benchmark.rb b/benchmarks/sequel/benchmark.rb new file mode 100644 index 00000000..f6fd67a6 --- /dev/null +++ b/benchmarks/sequel/benchmark.rb @@ -0,0 +1,66 @@ +require "harness" +require 'random/formatter' + +Dir.chdir __dir__ +use_gemfile + +require "sequel" + +# Sequel with common plugins & extensions +%i[ + escaped_like + migration + sql_log_normalizer + sqlite_json_ops +].each { |name| Sequel.extension name } + +DB = Sequel.sqlite + +DB.create_table :posts do + primary_key :id + String :title, null: false + String :body + String :type_name, null: false + String :key, null: false + Integer :upvotes, null: false + Integer :author_id, null: false + DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP + DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP +end + +%i[ + association_dependencies + auto_validations + json_serializer + nested_attributes + prepared_statements + require_valid_schema + subclasses + validation_helpers +].each { |name| Sequel::Model.plugin name } + +Sequel::Model.plugin :serialization, :json, :data +Sequel::Model.plugin :timestamps, update_on_create: true + +class Post < Sequel::Model +end + +10000.times { + Post.create(title: Random.alphanumeric(30), + type_name: Random.alphanumeric(10), + key: Random.alphanumeric(10), + body: Random.alphanumeric(100), + upvotes: rand(30), + author_id: rand(30)) +} + +# heat any caches +Post.where(id: 1).first.title + +run_benchmark(10) do + 1.upto(1000) do |i| + post = Post.where(id: i).first + "#{post.title}\n#{post.body}" + "type: #{post.type_name}, votes: #{post.upvotes}, updated on: #{post.updated_at}" + end +end