Skip to content

Instantly share code, notes, and snippets.

@jfine
jfine / with_indifferent_access_benchmark.rb
Last active September 13, 2022 14:32
Object::HashWithIndifferentAccess Benchmark
require 'benchmark'
require 'active_support/all'
n = 1_000_000
Benchmark.bm(25) do |x|
x.report("sm original:") { n.times { { foo: :bar } } }
x.report("sm w/ indifferent:") { n.times { { foo: :bar }.with_indifferent_access } }
x.report("md original:") { n.times { Hash[('a'..'z').zip('a'..'z')] } }
x.report("md w/ indifferent:") { n.times { Hash[('a'..'z').zip('a'..'z')].with_indifferent_access } }
end

Keybase proof

I hereby claim:

  • I am jfine on github.
  • I am jfine (https://keybase.io/jfine) on keybase.
  • I have a public key whose fingerprint is 761D C5F8 5DF0 87C4 D08B AE00 9772 8452 92B5 9C8D

To claim this, I am signing this object:

@jfine
jfine / gist:4151663b92f6f3a891f5
Last active August 29, 2015 14:07
Redirect GET www requests via Rails routes
# Redirect GET www requests
constraints(host: /^www\./i) do
get '(*path)', to: redirect(status: 302) do |params, request|
[request.scheme, '://', request.host.sub(/^www\./i, ''), request.fullpath].join
end
end