Skip to content

Instantly share code, notes, and snippets.

View casperisfine's full-sized avatar

Jean byroot Boussier casperisfine

View GitHub Profile
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
# 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"
# 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]
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)
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
./configure -C --disable-install-doc --prefix=/opt/rubies/scratch
# 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.
$ 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
# 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"
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"