def lineGraph():

    webScrapingTimes = [webScraping.main(n) for n in [1, 3, 5, 7, 10, 13, 16]]
    calculatePrimeTimes = [
        calculatePrime.main(n) for n in [1, 3, 5, 7, 10, 13, 16]
    ]
    compressionTimes = [compression.main(n) for n in [1, 3, 5, 7, 10, 13, 16]]
    encodingTimes = [encoding.main(n) for n in [1, 3, 5, 7, 10, 13, 16]]
    sortingTimes = [mysort.main(n) for n in [1, 3, 5, 7, 10, 13, 16]]
    fibonacciTimes = [fibonacci.main(n) for n in [1, 3, 5, 7, 10, 13, 16]]

    # Make a data frame
    df = pd.DataFrame({
        'Seconds': [1, 3, 5, 7, 10, 13, 16],
        'Web Scraping': webScrapingTimes,
        'Calculate Primes': calculatePrimeTimes,
        'Compression': compressionTimes,
        'Encoding': encodingTimes,
        'Sorting': sortingTimes,
        "Fibonacci": fibonacciTimes
    })

    plt.style.use('seaborn-darkgrid')

    # create a color palette
    palette = plt.get_cmap('Set1')
    # multiple line plot
    num = 0
    for column in df.drop('Seconds', axis=1):
        num += 1
        plt.plot(df['Seconds'],
                 df[column],
                 marker='',
                 color=palette(num),
                 linewidth=1,
                 alpha=0.9,
                 label=column)

    # Add legend
    plt.legend(loc=2, ncol=2)

    # Add titles
    plt.title("Multiprocessing Test",
              loc='left',
              fontsize=12,
              fontweight=0,
              color='orange')
    plt.xlabel("Processes")
    plt.ylabel("Seconds")
    plt.savefig('picture.png')
 def test_fibonacci_2(self):
     self.assertEqual(main(), 2880067194370816120)
 def test_fibonacci_1(self):
     self.assertEqual(main(), 55)
示例#4
0
def main():
    print("\n==========================================================================================="
          "\nWelcome to our program! We will be testing the multiprocessing module on various workloads.")
    while(True):
        option = (input(
            "\nPlease select from the following: \n"
            "1. Web Scraping\n"
            "2. Calculating Primes\n"
            "3. Compressing Text Files\n"
            "4. Encoding Image Files\n"
            "5. Sorting Integer Lists\n"
            "6. Fibonacci\n"
            "7. Show Graph\n"
            "8. Clean Workspace\n"
            "9. Quit Program\n"
            "Selection: "
        ))
        while(not (str.isdigit(option))):
            option = input("Please enter a valid number: ")

        option = int(option)
        if option == 1:
            print("\nWelcome to the Web Scraping Test!")
            print(
                "Here we will be using BeautifulSoup to CSV files container weekly weather for multiple cities!\n")
            num_process = getNumProcess()
            print("\n")
            for n in num_process:
                time_elapsed = webScraping.main(n)
                print("Test took {} seconds with {} processes.".format(
                    time_elapsed, n))

        elif option == 2:
            print("\nWelcome to the Prime Number Calculation Test!")
            print(
                "Here we will calculating the first million prime numbers\n")
            num_process = getNumProcess()
            print("\n")
            for n in num_process:
                time_elapsed = calculatePrime.main(n)
                print("Test took {} seconds with {} processes.".format(
                    time_elapsed, n))

        elif option == 3:
            print("\nWelcome to the File Compression Test!")
            print(
                "Here we will be compressing and uncompressing various Disney movie scripts using zlib!\n")
            num_process = getNumProcess()
            print("\n")
            for n in num_process:
                time_elapsed = compression.main(n)
                print("Test took {} seconds with {} processes.".format(
                    time_elapsed, n))

        elif option == 4:
            print("\nWelcome to the Encoding Test!")
            print(
                "Here we will be pulling images from Reddit and encoding them with unidecode!\n")
            num_process = getNumProcess()
            print("\n")
            for n in num_process:
                time_elapsed = encoding.main(n)
                print("Test took {} seconds with {} processes.".format(
                    time_elapsed, n))

        elif option == 5:
            print("\nWelcome to the Sorting Test!")
            print(
                "Here we will be sorting arrays of size 100000!\n")
            num_process = getNumProcess()
            print("\n")
            for n in num_process:
                time_elapsed = mysort.main(n)
                print("Test took {} seconds with {} processes.".format(
                    time_elapsed, n))
        elif option == 6:
            print("\nWelcome to the Fibonacci Test!")
            print(
                "Here we will be recursively calculating the first 15 fibonacci numbers!\n")
            num_process = getNumProcess()
            print("\n")
            for n in num_process:
                time_elapsed = fibonacci.main(n)
                print("Test took {} seconds with {} processes.".format(
                    time_elapsed, n))
        elif option == 7:
            print(
                "\nWe will export the graph as a png in the current directoy. This may take some time!\n")
            graphs.lineGraph()
            webScraping.clean()
            calculatePrime.clean()
            compression.clean()
            print("The png has been generated. Check the cwd!\n")
        elif option == 8:
            webScraping.clean()
            calculatePrime.clean()
            compression.clean()
            fibonacci.clean()
            print("Workspace has been cleaned!")
        elif option == 9:
            print("Thank you for using our program!")
            sys.exit(0)
        else:
            print("Please enter a valid option!")
            continue
 def test_fibonacci_7(self):
     self.assertEqual(main(), 190392490709135)
 def test_fibonacci_9(self):
     self.assertEqual(main(), 308061521170129)
 def test_fibonacci_6(self):
     self.assertEqual(main(), 1548008755920)
 def test_fibonacci_5(self):
     self.assertEqual(main(), 6765)
 def test_fibonacci_4(self):
     self.assertEqual(main(), 42868634127888159424995674777973502051063092312442448224088410550266867672)
 def test_fibonacci_5(self):
     self.assertEqual(main(), 6765)
 def test_fibonacci_3(self):
     self.assertEqual(main(), 354224848179261915075)
 def test_fibonacci_2(self):
     self.assertEqual(main(), 2880067194370816120)
 def test_fibonacci_1(self):
     self.assertEqual(main(), 55)
 def test_fibonacci_3(self):
     self.assertEqual(main(), 354224848179261915075)
 def test_fibonacci_7(self):
     self.assertEqual(main(), 190392490709135)
 def test_fibonacci_4(self):
     self.assertEqual(
         main(),
         42868634127888159424995674777973502051063092312442448224088410550266867672
     )
 def test_fibonacci_8(self):
     self.assertEqual(main(), 1100087778366101931)
 def test_fibonacci_6(self):
     self.assertEqual(main(), 1548008755920)
 def test_fibonacci_9(self):
     self.assertEqual(main(), 308061521170129)
 def test_fibonacci_8(self):
     self.assertEqual(main(), 1100087778366101931)
 def test_fibonacci_10(self):
     self.assertEqual(main(), 280571172992510140037611932413038677189525)
 def test_fibonacci_10(self):
     self.assertEqual(main(), 280571172992510140037611932413038677189525)
示例#23
0
 def test_three(self, stdout):
     main()
     self.assertEqual(stdout.getvalue(), "\n".join([
         '89',
     ]) + '\n')