Skip to content

Instantly share code, notes, and snippets.

🌐
building some part of the internet

Ryan McGeary rmm5t

🌐
building some part of the internet
Block or report user

Report or block rmm5t

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View _pg_searchable.md
@rmm5t
rmm5t / benchmark_array_product.rb
Created Jun 30, 2019
Benchmark Array#product
View benchmark_array_product.rb
require 'benchmark'
def test_nested_loop
1.upto(20) do |x|
1.upto(30) do |y|
x * y
end
end
end
@rmm5t
rmm5t / benchmark_lazy.rb
Last active Jun 23, 2019
Benchmark enumerator patterns
View benchmark_lazy.rb
require 'benchmark'
array = (1..1000).to_a
n = 1000
Benchmark.bmbm do |x|
x.report("lazy") { n.times { array.lazy.select(&:even?).map { |i| i / 2 }.to_a } }
x.report("double-pass") { n.times { array.select(&:even?).map { |i| i / 2 } } }
x.report("nested conditional") do
n.times do
@rmm5t
rmm5t / benchmark_command_object_vs_poro.rb
Last active Jun 18, 2019
Benchmarking command object pattern vs PORO
View benchmark_command_object_vs_poro.rb
require 'benchmark'
require 'active_support/all'
class CommandObject
def self.execute_with(arg)
new(arg).tap(&:run)
end
def initialize(arg)
@arg = arg
@rmm5t
rmm5t / benchmark_local_var_vs_instance_var.rb
Last active Jun 18, 2019
Benchmark local var caching vs direct method access
View benchmark_local_var_vs_instance_var.rb
require 'benchmark'
require 'active_support/all'
Source = Struct.new(:value, keyword_init: true)
def local_var_test(source)
value = source.value
return if value.nil?
value
end
@rmm5t
rmm5t / benchmark_instance_var_vs_delegate.rb
Last active Jun 18, 2019
Benchmark instance variable vs delegation
View benchmark_instance_var_vs_delegate.rb
require 'benchmark'
require 'active_support/all'
Source = Struct.new(:value, keyword_init: true)
class InstanceVarTest
attr_reader :source, :value
def initialize(source)
@source = source
@rmm5t
rmm5t / benchmark_tag_vs_interpolation.rb
Last active Jun 18, 2019
Benchmarking tag vs content_tag vs string interpolation
View benchmark_tag_vs_interpolation.rb
require 'benchmark'
require 'action_view'
include ActionView::Helpers::TagHelper
include ERB::Util
def output_buffer=(s)
end
def output_buffer
end
@rmm5t
rmm5t / benchmark_interpolation_vs_join.rb
Created May 28, 2019
Benchmark String interpolation vs Array#join
View benchmark_interpolation_vs_join.rb
require 'benchmark'
def test_interpolation(x, y)
"X#{x}Y#{y}"
end
def test_join(x, y)
["X", x, "Y", y].join
end
@rmm5t
rmm5t / benchmark_style_multiple_comparison.rb
Last active Jun 18, 2019
Style/MultipleComparison benchmark
View benchmark_style_multiple_comparison.rb
require 'benchmark'
def test_conditionals(n)
n == 1 || n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 7
end
def test_include(n)
[1, 2, 3, 4, 5, 6, 7].include?(n)
end
@rmm5t
rmm5t / _common_rake_tasks.md
Last active Mar 11, 2019
Common rake tasks I use on Rails projects
View _common_rake_tasks.md
You can’t perform that action at this time.