Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CONFIDENCE_THRESHOLD = 4
# A user with some attempts
user = User.find(12481)
Benchmark.ips do |x|
x.report("in ruby") do
Flashcard.
all.
map { |q| q.most_recent_attempt_for(user) }.
select { |a| a.confidence > 0 && a.confidence < CONFIDENCE_THRESHOLD }.
map(&:flashcard)
end
x.report("in views") do
LatestAttempt.by(user).
confidence_below(CONFIDENCE_THRESHOLD).
includes(:flashcard).
map(&:flashcard)
end
x.compare!
end
# Comparison:
# in views: 1793.6 i/s
# in ruby: 21.1 i/s - 85.11x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.