Skip to content

Instantly share code, notes, and snippets.

@siannopollo
siannopollo / README.md
Last active July 13, 2022 19:58 — forked from iamatypeofwalrus/README.md
Pluck in batches

pluck_in_batches

Sometimes you need to iterate over a ton of items and you don't want the overhead of creating AR objects out of all of them. Hell, you only need a few things! Well, #pluck has your back.

But what if you want to iterate over many tonnes of items?

Pluck in batches to the rescue!

Enjoy!

@siannopollo
siannopollo / benchmark.rb
Last active February 25, 2023 07:01 — forked from chanks/benchmark.rb
Benchmark haml vs. erb
require 'rubygems'
require 'benchmark'
require 'haml'
haml_template = File.read('template.haml')
erb_template = File.read('template.erb')
Benchmark.bm do |x|
x.report('haml:') { 1000.times{ Haml::Engine.new(haml_template).render } }
x.report('erb:') { 1000.times{ ERB.new(erb_template, nil, '-').src } }