Example #1
0
    def test_speed(self):
        """
        Function for testing speed of index building and generating speed perfomance result
        """
        df = pd.DataFrame(columns=['Process count', 'Speed (s)'])
        for proc_count in range(min(max(cpu_count(), 1), 12)):
            ind = Index('F:/aclImdb', 22, True)
            speed = timeit.timeit(lambda: ind.build(proc_count + 1), number=1)
            df = df.append(
                {
                    'Process count': int(proc_count),
                    'Speed (s)': speed
                },
                ignore_index=True)
            print(f'{proc_count=} : {speed} seconds')
            self.assertGreater(45, speed)
        ind = Index('F:/aclImdb', 22, True)
        speed = timeit.timeit(lambda: ind.build_sequential(), number=1)
        df = df.append(
            {
                'Process count': 'Sequential(optimized)',
                'Speed (s)': speed
            },
            ignore_index=True)

        for proc_count in range(min(max(cpu_count(), 1), 12)):
            ind = Index('F:/aclImdb', 22, False)
            speed = timeit.timeit(lambda: ind.build(proc_count + 1), number=1)
            df = df.append(
                {
                    'Process count': f'Variant only: {proc_count}',
                    'Speed (s)': speed
                },
                ignore_index=True)
            print(f'{proc_count=} : {speed} seconds')
            self.assertGreater(45, speed)
        ind = Index('F:/aclImdb', 22, False)
        speed = timeit.timeit(lambda: ind.build_sequential(), number=1)
        df = df.append(
            {
                'Process count': 'Variant only: Sequential(optimized)',
                'Speed (s)': speed
            },
            ignore_index=True)

        df.to_csv('test_results.csv', index=False)
Example #2
0
import timeit
from Index import Index
var = 22

if __name__ == '__main__':
    thread_count = int(input("Input thread count: "))
    print('Starting parallel index build...')
    ind = Index('F:/aclImdb', 22, True)
    print(timeit.timeit(lambda: ind.build(thread_count), number=1))
    print('Starting sequential index build...')
    ind2 = Index('F:/aclImdb', 22, True)
    print(timeit.timeit(lambda: ind2.build_sequential(), number=1))

    while (user_input := input('Enter words to search in index: ')) != '':
        for val in user_input.split(' '):
            print(val, ind.find(val))