This file contains hidden or 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 "active_support/all" | |
class Hash | |
def refined_symbolize_keys | |
transform_keys { |key| key.to_sym rescue key } | |
end | |
end | |
module HashRefinements |
This file contains hidden or 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
# frozen_string_literal: true | |
require "bigdecimal/util" | |
# Ref: https://github.com/ruby/ruby/commit/e1424c35012ccf1f3822c9046081b225aef4142e | |
# Ref: https://github.com/ruby/bigdecimal/issues/70 | |
# Ruby 3.0 changed the default precision used when calling `Float#to_d` from 15 to 16. | |
# It causes a whole lot of issues. I'm trying to figure out what can be done about it | |
# but in the meantime the only solution I see is to revert it back to 2.x behavior. | |
if RUBY_VERSION >= "3.0" |
This file contains hidden or 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
# frozen_string_literal: true | |
require 'benchmark/ips' | |
require 'active_support/all' | |
require 'zlib' | |
sizes = if ENV['SIZES'] | |
ENV['SIZES'].split(',').map(&:to_i) | |
else | |
[0, 10, 2_000] |
This file contains hidden or 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 'active_support/all' | |
require 'benchmark/ips' | |
class Module | |
def fake_cattr_accessor(sym) | |
private_getter = :"_#{sym}" | |
private_setter = :"_#{sym}=" | |
singleton_class.attr_accessor(private_getter) | |
singleton_class.send(:private, private_getter, private_setter) |
This file contains hidden or 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 'active_support/all' | |
class CVarBase | |
mattr_accessor :legacy_connection_handling, instance_writer: false, default: true | |
def self.connection_handlers | |
unless legacy_connection_handling | |
raise NotImplementedError, "The new connection handling does not support accessing multiple connection handlers." | |
end |
This file contains hidden or 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
./configure -C --disable-install-doc --prefix=/opt/rubies/scratch |
This file contains hidden or 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
# typed: false | |
# frozen_string_literal: true | |
# On MRI Symbols can be of two types: static or dynamic | |
# | |
# Static symbols are the ones explicitly referenced in the source code (`:foo`), and they're fake objects. | |
# Meaning they don't actually exists, they're just a special type of reference like integers. They use close to | |
# no memory, are particularly fast to compare and are not garbage collected. | |
# | |
# Dynamic symbols are symbols built using `String#to_sym` and that don't have an existing equivalent static symbol. |
This file contains hidden or 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 | |
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19] | |
$ ruby /tmp/struct.rb | |
Warming up -------------------------------------- | |
hash 1.450M i/100ms | |
naive 8.267k i/100ms | |
lazy-cached 68.069k i/100ms | |
explicit 415.985k i/100ms | |
Calculating ------------------------------------- | |
hash 14.223M (± 3.4%) i/s - 71.047M in 5.001074s |
This file contains hidden or 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
# frozen_string_literal: true | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" |
This file contains hidden or 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
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "activerecord" |