#!/urs/bin/env python3 """ sum_values.py This program has a sum_values(n) function that adds up the integers from 1 to n and returns that value. The main function runs through a series of tests of that function, with increasingly large values of n. The time it takes for each of those additions to occur is captured. The results of these tests are then written to an external CSV file. That CSV file can be imported into a spreadsheet program and analyzed with a trend line. @author Richard White @version 2018-02-14 """ import time def sum_values(n): """Sums the values from 1 to n, inclusive """ sums = 0 for i in range(1,n+1): sums += i return sums def main(): LOWER = 1000000 UPPER = 10000000 INTERVAL = 1000000 outfile = open('result.csv','w') for val in range(LOWER, UPPER, INTERVAL): time_initial = time.time() # test starts result = sum_values(val) # call function time_final = time.time() # test is completed print(val, time_final - time_initial) # prints on screen # writes results out to file outfile.write(str(val) + ',' + str(time_final - time_initial) + "\n") outfile.close() print("Results written out to result.csv") if __name__ == "__main__": main()