'Create large number of courses and give access of some of these courses to the user and
compare the time to fetch accessible courses for the user through traversing all courses and
reversing django groups'

@ddt.data((ModuleStoreEnum.Type.split, 4, 23), (ModuleStoreEnum.Type.mongo, USER_COURSES_COUNT, 2))
@ddt.unpack
def test_course_listing_performance(self, store, courses_list_from_group_calls, courses_list_calls):

    user_course_ids = random.sample(range(TOTAL_COURSES_COUNT), USER_COURSES_COUNT)
    with self.store.default_store(store):
        for number in range(TOTAL_COURSES_COUNT):
            org = 'Org{0}'.format(number)
            course = 'Course{0}'.format(number)
            run = 'Run{0}'.format(number)
            course_location = self.store.make_course_key(org, course, run)
            if (number in user_course_ids):
                self._create_course_with_access_groups(course_location, self.user, store=store)
            else:
                self._create_course_with_access_groups(course_location, store=store)
    with Timer() as iteration_over_courses_time_1:
        (courses_iter, __) = _accessible_courses_iter(self.request)
    self.assertEqual(len(list(courses_iter)), USER_COURSES_COUNT)
    with Timer() as iteration_over_courses_time_2:
        (courses_iter, __) = _accessible_courses_iter(self.request)
    self.assertEqual(len(list(courses_iter)), USER_COURSES_COUNT)
    with Timer() as iteration_over_groups_time_1:
        (courses_list, __) = _accessible_courses_list_from_groups(self.request)
    self.assertEqual(len(courses_list), USER_COURSES_COUNT)
    with Timer() as iteration_over_groups_time_2:
        (courses_list, __) = _accessible_courses_list_from_groups(self.request)
    self.assertEqual(len(courses_list), USER_COURSES_COUNT)
    with check_mongo_calls(courses_list_from_group_calls):
        _accessible_courses_list_from_groups(self.request)
    with check_mongo_calls(courses_list_calls):
        list(_accessible_courses_iter(self.request))
