Created
October 8, 2012 18:40
-
-
Save miwest929/3854127 to your computer and use it in GitHub Desktop.
test correctness of messaging_apps refactor + performance benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'set' | |
| namespace :query do | |
| task :validate => :environment do | |
| users = User.all | |
| differences = 0 | |
| failed_users = [] | |
| users.each do |u| | |
| old_apps = old_way u | |
| new_apps = u.messaging_apps | |
| old_set = Set.new old_apps | |
| new_set = Set.new new_apps | |
| is_same = (old_set == new_set) | |
| if is_same | |
| print "." | |
| else | |
| more_restrictive = old_set.length > new_set.length | |
| if more_restrictive | |
| print "." | |
| else | |
| print "F" | |
| differences += 1 | |
| failed_users << u.id | |
| end | |
| end | |
| end | |
| puts "" | |
| puts "There are #{differences} users that failed" | |
| puts "Here they are: #{failed_users}" | |
| end | |
| task :bm => :environment do | |
| users = User.all | |
| stime = Time.now | |
| users[0..10].each do |u| | |
| old_way u | |
| end | |
| etime = Time.now | |
| puts "Old way took #{etime - stime} seconds" | |
| stime = Time.now | |
| users[0..10].each do |u| | |
| u.messaging_apps | |
| end | |
| etime = Time.now | |
| puts "New way took #{etime - stime} seconds" | |
| end | |
| def old_way u | |
| invitations = (u.study_group_invitations + u.study_invitations + u.team_invitations).uniq | |
| invitations.collect {|x| x.app_assignments}.flatten.collect{|x| x.app}.uniq | |
| end | |
| def new_way u | |
| invitations = (u.study_group_invitations + u.study_invitations + u.team_invitations).uniq | |
| invitations.collect {|x| x.assigned_apps}.uniq | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment