def string_manipulation_tests(num_loops):
    profile_utils.add_string('----- String Concat Test -----')
    putting = 'Putting'
    strings = 'Strings'
    together = 'Together'
    is_var = 'is'
    fun = 'Fun'
    profile_utils.sub_time_start()
    string = ''
    for index in range(num_loops):
        string += putting + ' ' + strings + ' ' + together + ' ' + is_var + ' ' + fun
    profile_utils.sub_time_end('Python: += Putting + Strings + Together + Is + Fun')
    profile_utils.sub_time_start()
    string6 = ''
    for index in range(num_loops):
        string6.join((string6, putting.join((' ', strings, ' ', together, ' ', is_var, ' ', fun))))
    profile_utils.sub_time_end('Python: str.join(str, Putting.join(Strings, Together, Is, Fun))')
    profile_utils.sub_time_start()
    string2 = ''
    for index in range(num_loops):
        string2.join((string2, '{} {} {} {} {}'.format(putting, strings, together, is_var, fun)))
    profile_utils.sub_time_end('Python: str.join(str, .format(Putting, Strings, Together, Is, Fun))')
    profile_utils.sub_time_start()
    for index in range(num_loops):
        string3 = 'CurIndex: ' + str(index)
    profile_utils.sub_time_end('Python: str = CurIndex: + index')
    profile_utils.sub_time_start()
    for index in range(num_loops):
        string4 = 'CurIndex: {}'.format(index)
    profile_utils.sub_time_end('Python: = CurIndex.format(index)')
def no_op_test(num_loops):
    profile_utils.add_string('----- No Op Test -----')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        nothing_func()
    profile_utils.sub_time_end('Python: {} no_op calls'.format(num_loops))
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        no_op_function()
    profile_utils.sub_time_end('C++   : {} no_op calls'.format(num_loops))
Exemple #3
0
def no_op_test(num_loops):
    profile_utils.add_string('----- No Op Test -----')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        nothing_func()
    profile_utils.sub_time_end('Python: {} no_op calls'.format(num_loops))
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        no_op_function()
    profile_utils.sub_time_end('C++   : {} no_op calls'.format(num_loops))
Exemple #4
0
def math_tests(num_loops):
    profile_utils.add_string('----- Various Magnitude Calculation Tests -----')
    profile_utils.sub_time_start()
    value = 0
    for index in range(num_loops):
        value += math.sqrt(index * index + (index + 1 * index + 1))
    profile_utils.sub_time_end(
        'Python: {} 2d vector magnitude calcs, Val: {}'.format(
            num_loops, value))
    profile_utils.sub_time_start()
    value = full_magnitude(num_loops)
    profile_utils.sub_time_end(
        'Python: {} 2d vector magnitude calcs, all inside python function, Val: {}'
        .format(num_loops, value))
    profile_utils.sub_time_start()
    value = 0
    for index in range(num_loops):
        value += magnitude(index)
    profile_utils.sub_time_end(
        'Python: {} 2d vector magnitude calcs, PyLoop calls magnitude func, Val: {}'
        .format(num_loops, value))
    profile_utils.sub_time_start()
    value = manitude_test_function(num_loops)
    profile_utils.sub_time_end(
        'C++   : {} 2d vector magnitude calcs, Loop in C++, Val: {}'.format(
            num_loops, value))
def list_comp_test(num_loops):
    profile_utils.add_string('----- List Comprehension Test -----')
    r0 = sims4.geometry.QtRect(Vector2(0, 0), Vector2(1, 1))
    r1 = sims4.geometry.QtRect(Vector2(0, 0), Vector2(2, 2))
    rect_list = []
    for _ in range(500):
        rect_list.append(r0)
        rect_list.append(r1)
    profile_utils.sub_time_start()
    new_list = []
    for rect in rect_list:
        new_list.append(rect.a)
    profile_utils.sub_time_end('Python: {} list appends & C++ accessor'.format(num_loops))
    profile_utils.sub_time_start()
    new_list2 = [rect.a for rect in rect_list]
    profile_utils.sub_time_end('Python: {} list appends & C++ accessor : list comprehension'.format(num_loops))
Exemple #6
0
def list_comp_test(num_loops):
    profile_utils.add_string('----- List Comprehension Test -----')
    r0 = sims4.geometry.QtRect(Vector2(0, 0), Vector2(1, 1))
    r1 = sims4.geometry.QtRect(Vector2(0, 0), Vector2(2, 2))
    rect_list = []
    for _ in range(500):
        rect_list.append(r0)
        rect_list.append(r1)
    profile_utils.sub_time_start()
    new_list = []
    for rect in rect_list:
        new_list.append(rect.a)
    profile_utils.sub_time_end(
        'Python: {} list appends & C++ accessor'.format(num_loops))
    profile_utils.sub_time_start()
    new_list2 = [rect.a for rect in rect_list]
    profile_utils.sub_time_end(
        'Python: {} list appends & C++ accessor : list comprehension'.format(
            num_loops))
Exemple #7
0
def string_manipulation_tests(num_loops):
    profile_utils.add_string('----- String Concat Test -----')
    putting = 'Putting'
    strings = 'Strings'
    together = 'Together'
    is_var = 'is'
    fun = 'Fun'
    profile_utils.sub_time_start()
    string = ''
    for index in range(num_loops):
        string += putting + ' ' + strings + ' ' + together + ' ' + is_var + ' ' + fun
    profile_utils.sub_time_end(
        'Python: += Putting + Strings + Together + Is + Fun')
    profile_utils.sub_time_start()
    string6 = ''
    for index in range(num_loops):
        string6.join(
            (string6,
             putting.join(
                 (' ', strings, ' ', together, ' ', is_var, ' ', fun))))
    profile_utils.sub_time_end(
        'Python: str.join(str, Putting.join(Strings, Together, Is, Fun))')
    profile_utils.sub_time_start()
    string2 = ''
    for index in range(num_loops):
        string2.join((string2, '{} {} {} {} {}'.format(putting, strings,
                                                       together, is_var, fun)))
    profile_utils.sub_time_end(
        'Python: str.join(str, .format(Putting, Strings, Together, Is, Fun))')
    profile_utils.sub_time_start()
    for index in range(num_loops):
        string3 = 'CurIndex: ' + str(index)
    profile_utils.sub_time_end('Python: str = CurIndex: + index')
    profile_utils.sub_time_start()
    for index in range(num_loops):
        string4 = 'CurIndex: {}'.format(index)
    profile_utils.sub_time_end('Python: = CurIndex.format(index)')
def math_tests(num_loops):
    profile_utils.add_string('----- Various Magnitude Calculation Tests -----')
    profile_utils.sub_time_start()
    value = 0
    for index in range(num_loops):
        value += math.sqrt(index*index + (index + 1*index + 1))
    profile_utils.sub_time_end('Python: {} 2d vector magnitude calcs, Val: {}'.format(num_loops, value))
    profile_utils.sub_time_start()
    value = full_magnitude(num_loops)
    profile_utils.sub_time_end('Python: {} 2d vector magnitude calcs, all inside python function, Val: {}'.format(num_loops, value))
    profile_utils.sub_time_start()
    value = 0
    for index in range(num_loops):
        value += magnitude(index)
    profile_utils.sub_time_end('Python: {} 2d vector magnitude calcs, PyLoop calls magnitude func, Val: {}'.format(num_loops, value))
    profile_utils.sub_time_start()
    value = manitude_test_function(num_loops)
    profile_utils.sub_time_end('C++   : {} 2d vector magnitude calcs, Loop in C++, Val: {}'.format(num_loops, value))
def dictionary_tests(num_loops):
    profile_utils.add_string('----- Dictionary Test -----')
    the_dict = {}
    string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    for char in string:
        the_dict[char] = 5
    the_dict['this_item'] = 15
    for char in string:
        the_dict[char + char] = 10
    temp_var = 0
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        while 'this_item' in the_dict:
            temp_var = the_dict['this_item']
    profile_utils.sub_time_end('Python: if "this_item" in the_dict, then lookup (hits)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        try:
            temp_var = the_dict['this_item']
        except KeyError:
            pass
    profile_utils.sub_time_end('Python: try: temp_var = the_dict["this_item"] (hits)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        temp_var = the_dict.get('this_item', None)
    profile_utils.sub_time_end('Python: the_dict.get("this_item", None) (hits)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        if 'this_item_not_here' in the_dict:
            temp_var = the_dict['this_item_not_here']
        else:
            temp_var = None
    profile_utils.sub_time_end('Python: if "this_item_not_here" in the_dict:, then lookup (miss)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        try:
            temp_var = the_dict['this_item_not_here']
        except KeyError:
            temp_var = None
    profile_utils.sub_time_end('Python: try: temp_var = the_dict["this_item_not_here"] (miss)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        temp_var = the_dict.get('this_item_not_here', None)
    profile_utils.sub_time_end('Python: the_dict.get("this_item_not_here", None) (miss)')
    return temp_var
Exemple #10
0
def dictionary_tests(num_loops):
    profile_utils.add_string('----- Dictionary Test -----')
    the_dict = {}
    string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    for char in string:
        the_dict[char] = 5
    the_dict['this_item'] = 15
    for char in string:
        the_dict[char + char] = 10
    temp_var = 0
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        if 'this_item' in the_dict:
            temp_var = the_dict['this_item']
    profile_utils.sub_time_end(
        'Python: if "this_item" in the_dict, then lookup (hits)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        try:
            temp_var = the_dict['this_item']
        except KeyError:
            pass
    profile_utils.sub_time_end(
        'Python: try: temp_var = the_dict["this_item"] (hits)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        temp_var = the_dict.get('this_item', None)
    profile_utils.sub_time_end(
        'Python: the_dict.get("this_item", None) (hits)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        if 'this_item_not_here' in the_dict:
            temp_var = the_dict['this_item_not_here']
        else:
            temp_var = None
    profile_utils.sub_time_end(
        'Python: if "this_item_not_here" in the_dict:, then lookup (miss)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        try:
            temp_var = the_dict['this_item_not_here']
        except KeyError:
            temp_var = None
    profile_utils.sub_time_end(
        'Python: try: temp_var = the_dict["this_item_not_here"] (miss)')
    profile_utils.sub_time_start()
    for _ in range(num_loops):
        temp_var = the_dict.get('this_item_not_here', None)
    profile_utils.sub_time_end(
        'Python: the_dict.get("this_item_not_here", None) (miss)')
    return temp_var