Sha256: 979ad09884f3f8d7218d87f26b262c5ca13330bf5f7e5d052b1eb9fdfffb2fc5

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

class UserBenchmarkSpec < MiniTest::Unit::TestCase
  def test_update_recommendations
    if ENV["BENCH"] then
      Recommendable.redis.flushdb
      @actions = [:like, :dislike]

      puts "\n"
      
      assert_performance_exponential do |n|
        @user = Factory(:user)
        @users = []
        @movies = []

        # Make n users, 5n movies
        n.times do
          @users << Factory(:user)
          @movies << Factory(:movie)
          @movies << Factory(:movie)
          @movies << Factory(:movie)
          @movies << Factory(:movie)
          @movies << Factory(:movie)
        end
  
        # Main user randomly likes/dislikes 1/4 of the movies
        @movies.sample(n/4).each do |m|
          @user.send(@actions.sample, m)
        end
  
        # Other users randomly like/dislike some movies
        @movies.sample(n/2).each do |m|
          @users.sample.send(@actions.sample, m)
          @users.sample.send(@actions.sample, m)
          @users.sample.send(@actions.sample, m)
        end
  
        @user.send :update_similarities
        @user.send :update_recommendations
        Recommendable.redis.flushdb

        User.delete_all
        Movie.delete_all
        Recommendable::Like.delete_all
        Recommendable::Dislike.delete_all
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
recommendable-1.1.7 spec/models/user_benchmark_spec.rb
recommendable-1.1.6 spec/models/user_benchmark_spec.rb
recommendable-1.1.5 spec/models/user_benchmark_spec.rb
recommendable-1.1.4 spec/models/user_benchmark_spec.rb
recommendable-1.1.3 spec/models/user_benchmark_spec.rb
recommendable-1.1.2 spec/models/user_benchmark_spec.rb
recommendable-1.1.1 spec/models/user_benchmark_spec.rb
recommendable-1.0.0 spec/models/user_benchmark_spec.rb
recommendable-0.2.1.1 spec/models/user_benchmark_spec.rb
recommendable-0.1.8 spec/models/user_benchmark_spec.rb
recommendable-0.1.6 spec/models/user_benchmark_spec.rb
recommendable-0.1.5 spec/models/user_benchmark_spec.rb
recommendable-0.1.4 spec/models/user_benchmark_spec.rb
recommendable-0.1.3 spec/models/user_benchmark_spec.rb