Skip to content

Instantly share code, notes, and snippets.

Avatar

Jean byroot Boussier casperisfine

View GitHub Profile
View cattr-bench.rb
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)
View bench.rb
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
View ruby.sh
./configure -C --disable-install-doc --prefix=/opt/rubies/scratch
View symbols_cache.rb
# 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.
View results.txt
$ 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
View aws-profile.rb
# 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"
View enum.rb
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"
View dangerous-methods.rb
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord'
gem 'benchmark-ips'
end
require 'benchmark/ips'
View lmdb.rb
require 'fileutils'
require 'lmdb'
require 'benchmark/ips'
PATH = __FILE__
MAX_SIZE = 134217728 # 128 MB
FileUtils.mkdir_p('/tmp/lmdb-bench')
@env = ::LMDB.new('/tmp/lmdb-bench', mapsize: MAX_SIZE, nometasync: true, nosync: true)
@database = @env.database('bootsnap', create: true)
View tar-gz-each.rb
require 'zlib'
require 'benchmark'
require 'rubygems/package'
require 'rubygems/package/tar_reader'
duration = Benchmark.realtime do
tar = Gem::Package::TarReader.new(Zlib::GzipReader.open(ARGV.first))
tar.each { |_| }
end