Editing Ulam spiral generators This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Both me and my dad wrote a ulam matrix generator, and mine is bigger when compiled with closure. So I now want to prove that mine is faster. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script> function ulam_qmacro(b,a,e,f){if(b==a||b==a+1)if(0<e&&e<=b&&0<f&&f<=a){a=[Math.floor(b/2)+b%2,Math.floor(a/2)+1];b=a[0];a=a[1];var g=1,h=1,c=1,d=0,j=1,k=1;do{for(var l=0;2>l;l++){for(var m=0;m<h;m++){if(b==e&&a==f)return g;g++;b+=c;a+=d}0==c?(c=-1*j,k=d,d=0):(d=-1*k,j=c,c=0)}h++}while(9999999>g)}else console.log("Invalid PX and PY combination");else console.log("Invalid W and H combination")}; function f(b,a){if(0===a%2)return b[0]!=a&&1!=b[1]?!0:!1;if(1===a%2)return 1!=b[0]&&b[1]!=a?!0:!1} function ulam_jcla1(b,a){var c;1>b[0]||1>b[1]||b[0]>a||b[1]>a||1>a?(console.log("Invalid values!"),c=!1):c=!0;if(!c)return-1;for(;f(b,a);){c=b;var d=a;0===d%2?c[1]-=1:1===d%2&&(c[0]-=1);b=c;a-=1}c=-1;var d=b[0],e=b[1];0===a%2?1===b[1]?c=Math.pow(a,2)-(b[0]-1):b[1]===a?c=Math.pow(a,2)-2*(a-1)-(a-2)+(d-1)-1:1===b[0]?c=Math.pow(a,2)-3*(a-1)-(a-2)+(e-2):b[0]===a&&(c=Math.pow(a,2)-a-(e-2)):1===a%2&&(1===b[1]?c=Math.pow(a,2)-2*(a-1)-(d-1):b[1]===a?c=Math.pow(a,2)-(a-1)+(d-1):1===b[0]?c=Math.pow(a,2)-2* (a-1)+(e-1):b[0]===a&&(c=Math.pow(a,2)-3*(a-1)-(e-1)));return c}; </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code for(var i = 0; i < 10000; i++){ulam_jcla1([3, 5], 6);} Test 2 Title Async (check if this is an asynchronous test) Code for(var i = 0; i < 10000; i++){ulam_qmacro(6,6,3,5);} Test 3 Title Async (check if this is an asynchronous test) Code ulam_jcla1([154823, 157623], 1548230); Test 4 Title Async (check if this is an asynchronous test) Code ulam_qmacro(1548230, 1548230, 154823, 157623 ); Test 5 Title Async (check if this is an asynchronous test) Code for(var i = 0; i < 100; i++){ulam_jcla1([50, 50], 1548230);} Test 6 Title Async (check if this is an asynchronous test) Code for(var i = 0; i < 100; i++){ulam_qmacro(1548230, 1548230, 50, 50 );}