diff --git a/1. log(n) behavior/TimingResults.ipynb b/1. log(n) behavior/TimingResults.ipynb new file mode 100644 index 0000000..26786a5 --- /dev/null +++ b/1. log(n) behavior/TimingResults.ipynb @@ -0,0 +1,65 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Timing Results\n", + "You can output the timing results on your own to validate the different behaviors. Note how slowly Loop() performs when compared against Set.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "N\tSum \tSet\t String\t Loop\n", + "2\t0.000180\t0.000405\t0.000790\t0.000683\n", + "4\t0.000245\t0.000543\t0.001301\t0.001412\n", + "8\t0.000594\t0.000906\t0.002686\t0.004765\n", + "16\t0.000702\t0.001796\t0.006847\t0.018192\n", + "32\t0.002404\t0.006432\t0.012565\t0.040191\n", + "64\t0.002454\t0.005637\t0.033022\t0.172966\n" + ] + } + ], + "source": [ + "from timing import outputTiming,sumValues,uniqueCheckLoop,uniqueCheckSet,uniqueCheckString\n", + "\n", + "outputTiming(7)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/1. log(n) behavior/timing.py b/1. log(n) behavior/timing.py index a958c24..0400652 100644 --- a/1. log(n) behavior/timing.py +++ b/1. log(n) behavior/timing.py @@ -86,7 +86,7 @@ def testCheckSlowest(self): self.assertTrue(uniqueCheckLoop(self.numbersWithDuplicate)) self.assertFalse(uniqueCheckLoop(self.numbers)) -def outputTiming(): +def outputTiming(end): """ Generate timing report using random integers from 0 to 16777216, which greatly reduces the chance that a duplicate exists, thus @@ -94,7 +94,7 @@ def outputTiming(): to produce identical number sets across different approaches. """ print ('N\tSum \tSet\t String\t Loop') - for trial in [2**_ for _ in range(1,11)]: + for trial in [2**_ for _ in range(1,end)]: numbers = f'[random.randint(0, 2 ** 24) for _ in range({trial})]' methods = ['sumValues', 'uniqueCheckSet', 'uniqueCheckString', 'uniqueCheckLoop' ] @@ -107,7 +107,7 @@ def outputTiming(): print (f'{trial}\t{results}') if __name__ == '__main__': - outputTiming() + outputTiming(9) unittest.main()