Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/sequel/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"
gem "sequel", "~> 5.63"
gem "sqlite3", "~> 1.4", platform: :ruby
17 changes: 17 additions & 0 deletions benchmarks/sequel/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions benchmarks/sequel/benchmark.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this is actually an inefficient way to query a record in Sequel, Post[i] or Post.first(id: i) are much faster: #207

"#{post.title}\n#{post.body}"
"type: #{post.type_name}, votes: #{post.upvotes}, updated on: #{post.updated_at}"
end
end