Skip to content

Instantly share code, notes, and snippets.

@tribalvibes
tribalvibes / def_benchmark.rb
Created August 3, 2011 19:42
calling ruby method defined via define_method is 50% slower than via class_eval
# define benchmark from:
#http://www.mathewabonyi.com/articles/2007/01/11/surprise-10min-benchmark-eval-class_eval-instance_eval-define_method-bind#trackbacks
# but we're interested in the speed of calling the method not only defining it
# results with ruby 1.9.2-p180 on mbp i7
require 'benchmark'
class A; def meth1; true; end; end
@tribalvibes
tribalvibes / find_in.rb
Created June 2, 2011 05:02
Implement SUNIONSTORE volatile find keys for Ohm
def keys(hash)
model.debug("#{model.name}.find: #{key} : #{hash}")
[].tap do |keys|
hash.each do |attr, values|
# nb: String is Enumerable in 1.8.x...
attr_type = model.types[attr]
if !(Enumerable === values) || ( attr_type && attr_type < Enumerable && attr_type != String )
Array(values).each do |v|
keys << model.index_key_for(attr, v)
end