This is a quick-n-dirty ActiveRecord module to quickly add full-text capabilities to a PostgreSQL table wihtout too much overhead.
Author: Ryan McGeary : http://github.com/rmm5t
License: MIT : https://rmm5t.mit-license.org/
This is a quick-n-dirty ActiveRecord module to quickly add full-text capabilities to a PostgreSQL table wihtout too much overhead.
Author: Ryan McGeary : http://github.com/rmm5t
License: MIT : https://rmm5t.mit-license.org/
| require 'benchmark' | |
| def test_nested_loop | |
| 1.upto(20) do |x| | |
| 1.upto(30) do |y| | |
| x * y | |
| end | |
| end | |
| end |
| 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 |
| require 'benchmark' | |
| require 'active_support/all' | |
| class CommandObject | |
| def self.execute_with(arg) | |
| new(arg).tap(&:run) | |
| end | |
| def initialize(arg) | |
| @arg = arg |
| 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 |
| require 'benchmark' | |
| require 'active_support/all' | |
| Source = Struct.new(:value, keyword_init: true) | |
| class InstanceVarTest | |
| attr_reader :source, :value | |
| def initialize(source) | |
| @source = source |
| require 'benchmark' | |
| require 'action_view' | |
| include ActionView::Helpers::TagHelper | |
| include ERB::Util | |
| def output_buffer=(s) | |
| end | |
| def output_buffer | |
| end |
| require 'benchmark' | |
| def test_interpolation(x, y) | |
| "X#{x}Y#{y}" | |
| end | |
| def test_join(x, y) | |
| ["X", x, "Y", y].join | |
| end |
| 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 |
These are common rake tasks that I include in most of my Rails projects (under lib/tasks)
Author: Ryan McGeary : http://github.com/rmm5t
License: MIT : https://rmm5t.mit-license.org/