Each one is original first, then OJ.
rake benchmarks:single_object_with_render:
#original
Calculating -------------------------------------
jbuilder 30 i/100ms
active_model_serializers
jruby-1.7.4 :769 > Neo4j._query("start n=node(*) match (n) where n.username! =~ '(?i)chrISTOpher' return n").first[:n].username | |
=> "christopher" | |
u = Neo4j._query("start n=node(*) match (n) where n.subject! =~ '[a-z\s]+?at[a-z\s]+?' or n.username! =~ '[a-z]+?man[a-z]+?' return n").to_a |
#copy and paste into rails console to play | |
module DumbHasMany | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def has_many(method, args=nil) | |
if args.nil? || !args.is_a?(Hash) | |
type = method | |
else |
[Student, Lesson, Teacher, Exam].each{|c| c.destroy_all } | |
ss101 = Lesson.create(subject: 'Social Studies', level: 101) | |
ss102 = Lesson.create(subject: 'Social Studies', level: 102) | |
math101 = Lesson.create(subject: 'Math', level: 101) | |
math201 = Lesson.create(subject: 'Math', level: 201) | |
geo103 = Lesson.create(subject: 'Geography', level: 103) | |
sandra = Student.create(name: 'Sandra', age: 16) | |
danny = Student.create(name: 'Danny', age: 15) |
def my_inject(initial = nil, sym = nil) | |
memo, starter = initial, self if initial && block_given? | |
memo, starter = self[0], self[1..-1] if initial.nil? || !block_given? | |
starter.push(initial) unless sym.nil? || block_given? | |
starter.my_each do |x| | |
if sym | |
memo = memo.send(sym, x) | |
elsif block_given? | |
memo = yield(memo,x) | |
else |
ORIGINAL | |
2.1.2 :002 > Benchmark.ips do |x| | |
2.1.2 :003 > x.config(:time => 5, :warmup => 2) | |
2.1.2 :004?> x.time = 10 | |
2.1.2 :005?> x.warmup = 2 | |
2.1.2 :006?> x.report("query") { Student.limit(900).each { |s| } } | |
2.1.2 :007?> end | |
Calculating ------------------------------------- | |
query CYPHER 26ms MATCH (result:`Student`) RETURN result LIMIT 900 |
# /u/zaclacgit on Reddit posted a topic the other day asking for thoughts on his exercise of | |
# recreating some basic enumerable methods. I gave him some tips on refactoring one method in particular | |
# and a few days later, he asked me to elaborate. I thought the easiest way might be to go through each | |
# step of the refactor and I'd get a nice blog post out of it in the process. | |
# To use this, start by commenting out each `my_inject` definition except the first. As you encounter | |
# new ones, uncomment them. Save this file as `refactor.rb` in the folder of your choice, ensure you have | |
# the rspec gem installed and run `rspec refactor.rb` from CLI to execute. | |
# Before we write a line of code, we're going to write specs based off of the simple comparisons |
[ | |
{ | |
"columns": [ | |
"r" | |
], | |
"data": [ | |
{ | |
"row": [ | |
{ | |
"_classname": "StudentLesson" |
class Movie | |
include Neo4j::ActiveNode | |
id_property :title | |
has_many :in, :actors, model_class: :Person, rel_class: Engagement | |
end | |
class Engagement | |
include Neo4j::ActiveRel | |
from_class Person | |
to_class Movie |
Each one is original first, then OJ.
rake benchmarks:single_object_with_render:
#original
Calculating -------------------------------------
jbuilder 30 i/100ms
active_model_serializers
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
x.config(warmup: 1, time: 5) | |
def test1 | |
a = [:foo, :bar, :baz, :omg, :wtf, :gtfo] | |
a.map(&:to_s) | |
end |