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
For a parametrized approach, you can add a helper into ApplicationHelper: | |
``` | |
def svg_tag(options = {}, class:) | |
tag.svg(xmlns: 'http://www.w3.org/2000/svg', class:, **options) do | |
yield if block_given? | |
end | |
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
Warming up -------------------------------------- | |
lookup 1.241M i/100ms | |
const_get 1.111M i/100ms | |
Calculating ------------------------------------- | |
lookup 13.510M (± 0.7%) i/s - 135.305M in 10.031861s | |
const_get 11.373M (± 0.5%) i/s - 114.446M in 10.072033s | |
with 95.0% confidence | |
Comparison: | |
lookup: 13509513.8 i/s |
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
An interesting line-up of articles about DCI pattern in Ruby and methods cache in MRI | |
(one of the reasons to avoid OpenStruct is methods cache invalidation on every OpenStruct instantiation): | |
https://tonyarcieri.com/dci-in-ruby-is-completely-broken | |
https://dec0de.me/2013/02/dci-performance | |
https://jamesgolick.com/2013/4/14/mris-method-caches.html | |
https://shopify.engineering/17489064-tuning-rubys-global-method-cache | |
https://mensfeld.pl/2015/04/ruby-global-method-cache-invalidation-impact-on-a-single-and-multithreaded-applications/ | |
https://tenderlovemaking.com/2015/12/23/inline-caching-in-mri.html |
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
/bin/bash -c "/Users/thunder/.rvm/bin/rvm ruby-2.3.7@mejuri do /Users/thunder/.rvm/rubies/ruby-2.3.7/bin/ruby '/Users/thunder/Library/Application Support/JetBrains/RubyMine2020.2/scratches/scratch.rb'" | |
Warming up -------------------------------------- | |
Direct interpolation 426.585k i/100ms | |
Percent interpolation | |
232.103k i/100ms | |
Plus concatenation 507.047k i/100ms | |
Calculating ------------------------------------- | |
Direct interpolation 4.393M (± 0.3%) i/s - 43.938M in 10.005452s | |
Percent interpolation |
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
brew install rbenv/tap/[email protected] | |
rvm reinstall ruby-2.2.0 --with-openssl-dir='/usr/local/opt/[email protected]' |
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
/bin/bash -c "/home/thunder/.rvm/bin/rvm ruby-2.5.1 do /home/thunder/.rvm/rubies/ruby-2.5.1/bin/ruby /home/thunder/.RubyMine2019.3/config/scratches/scratch_1.rb" | |
Warming up -------------------------------------- | |
Active Support symbolize_keys | |
37.892k i/100ms | |
Hash keys map to_sym 60.148k i/100ms | |
Calculating ------------------------------------- | |
Active Support symbolize_keys | |
562.840k (± 1.4%) i/s - 5.608M in 10.047830s | |
Hash keys map to_sym 767.850k (± 1.1%) i/s - 7.699M in 10.048546s | |
with 95.0% confidence |
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
13:30 $ rvm ls | |
ruby-2.4.9 [ x86_64 ] | |
=> ruby-2.5.1 [ x86_64 ] | |
* ruby-2.5.5 [ x86_64 ] | |
ruby-2.5.7 [ x86_64 ] | |
ruby-2.6.5 [ x86_64 ] | |
13:28 $ ruby poro_vs_attr_extras.rb | |
Warming up -------------------------------------- |
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 | |
# Install the necessary gems: | |
# gem install benchmark-ips | |
# gem install kalibera | |
require 'benchmark/ips' | |
ARRAY = (1..100).to_a.map { |e| [e, e] } |
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
Warming up -------------------------------------- | |
assign&return 21.225k i/100ms | |
each 23.473k i/100ms | |
merge 3.283k i/100ms | |
merge! 9.870k i/100ms | |
map with tuples 19.764k i/100ms | |
each_with_object 21.362k i/100ms | |
Calculating ------------------------------------- | |
assign&return 229.939k (± 5.2%) i/s - 2.314M in 10.087643s | |
each 256.244k (± 7.3%) i/s - 2.559M in 10.028367s |
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
Legend: | |
=> in the meaning column means there's a non-boolean return value | |
empty columns in Prior Name mean the method didn't exist before | |
* before a new method name means it's an alias to the prior method | |
Prior Name New Name Meaning | |
attribute_was(attr_name) *attribute_in_database(attr_name) current database value of attribute | |
attribute_change(attr_name) *attribute_change_to_be_saved => the changed value for attribute | |
attribute_changed?(attr_name) *will_save_change_to_attribute?(attr_name) was attribute modified since last save |
NewerOlder