$ brew install cloc
$ bundle install
ActiveRecord vs Sequel (require time)
require "yaml" | |
def lib_dir(gem_name) | |
gem = Gem::Specification.find_by_name(gem_name) | |
File.join(gem.full_gem_path, gem.require_path) | |
end | |
def loc(gem_name) | |
output = `cloc #{lib_dir(gem_name)} --yaml` | |
yaml = output.lines[6..-1].join("\n") | |
YAML.load(yaml)["Ruby"]["code"] | |
end | |
sequel_loc = loc("sequel") | |
activerecord_loc = loc("activerecord") + | |
loc("arel") + | |
loc("activemodel") + | |
loc("squeel") | |
puts "Sequel LOC: #{sequel_loc}" | |
puts "ActiveRecord LOC: #{activerecord_loc}" | |
# Sequel LOC: 31277 | |
# ActiveRecord LOC: 27384 |
require "benchmark" | |
require "sqlite3" | |
def require_sequel | |
require "sequel" | |
Sequel.sqlite | |
end | |
def require_activerecord | |
require "active_record" | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
files("activerecord").grep(/association/).each &method(:require) | |
require "squeel" | |
end | |
def files(gem_name) | |
gem = Gem::Specification.find_by_name(gem_name) | |
lib_dir = File.join(gem.full_gem_path, gem.require_path) | |
files = Dir["#{lib_dir}/**/*.rb"] | |
end | |
puts "Sequel load time: #{Benchmark.realtime{require_sequel}}" | |
puts "ActiveRecord load time: #{Benchmark.realtime{require_activerecord}}" | |
# Sequel load time: 0.08 | |
# ActiveRecord load time: 0.4 (5 times slower) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Why do you require
squeel
inside therequire_activerecord
method? If you're benchmarking the require time of both gems I'd assume you only require them.