Java:
- Changed PythagoreanSpeed program so that it recorded run time in nanoseconds rather than milliseconds. Tweaked the output slightly
- I set it to do 100 passes at levels 50, 100, 500, and 1000:
Timings: =======(n = 50)======= Strategy UMD solution: 0.1177920396039604 ms. Strategy UMD solution with Math.pow: 0.7689506237623762 ms. Strategy UMD solution with pre-squared array: 0.1406431188118812 ms. Strategy pre-squared with hash: 0.23302989108910893 ms. =======(n = 100)======= Strategy UMD solution: 0.2192501683168317 ms. Strategy UMD solution with Math.pow: 1.022717900990099 ms. Strategy UMD solution with pre-squared array: 0.15266823762376236 ms. Strategy pre-squared with hash: 0.21271922772277227 ms. =======(n = 500)======= Strategy UMD solution: 17.247952891089106 ms. Strategy UMD solution with Math.pow: 126.09220794059407 ms. Strategy UMD solution with pre-squared array: 12.931144465346534 ms. Strategy pre-squared with hash: 1.3764326336633663 ms. =======(n = 1000)======= Strategy UMD solution: 132.50848051485147 ms. Strategy UMD solution with Math.pow: 1036.010291940594 ms. Strategy UMD solution with pre-squared array: 100.51113749504951 ms. Strategy pre-squared with hash: 5.131068326732674 ms.
- I didn't add any code to round the output, so past the hundreds place or so those digits are probably not significant
- Pushed changes to github
- I then added an additional algorithm which is O(n2log(n)). All other conditions were kept the same.
- Github link to algorithm
Timings: =======(n = 50)======= Strategy UMD solution: 0.12460728712871287 ms. Strategy UMD solution with Math.pow: 0.8824542277227723 ms. Strategy UMD solution with pre-squared array: 0.09626874257425742 ms. Strategy pre-squared with hash: 0.24894374257425742 ms. Strategy pre-squared with binary search: 0.14212682178217823 ms. =======(n = 100)======= Strategy UMD solution: 0.24023814851485148 ms. Strategy UMD solution with Math.pow: 1.1169474059405942 ms. Strategy UMD solution with pre-squared array: 0.23458126732673265 ms. Strategy pre-squared with hash: 0.2551629306930693 ms. Strategy pre-squared with binary search: 0.21795613861386137 ms. =======(n = 500)======= Strategy UMD solution: 17.942774574257427 ms. Strategy UMD solution with Math.pow: 126.00360138613861 ms. Strategy UMD solution with pre-squared array: 13.263654326732674 ms. Strategy pre-squared with hash: 1.4827347524752474 ms. Strategy pre-squared with binary search: 5.845997277227723 ms. =======(n = 1000)======= Strategy UMD solution: 132.98607085148515 ms. Strategy UMD solution with Math.pow: 1002.6387993267326 ms. Strategy UMD solution with pre-squared array: 100.78688199009902 ms. Strategy pre-squared with hash: 5.523412445544555 ms. Strategy pre-squared with binary search: 32.41068194059406 ms.
- It's interesting that the binary search algorithm is actually faster at low values of n, likely because a hash of the values doesn't need to be created.
No comments:
Post a Comment