{"id":316,"date":"2021-03-18T16:09:13","date_gmt":"2021-03-18T16:09:13","guid":{"rendered":"http:\/\/www.volucer.it\/?p=316"},"modified":"2021-03-18T16:10:38","modified_gmt":"2021-03-18T16:10:38","slug":"on-browser-javascript-engine","status":"publish","type":"post","link":"https:\/\/www.volucer.it\/?p=316","title":{"rendered":"ON BROWSER JAVASCRIPT ENGINE"},"content":{"rendered":"\n<p><strong>JAVASCRIPT EXECUTION LIMITS IN THE WEB BROWSER<\/strong><\/p>\n\n\n\n<p>When we ask the visualization of a web page in the browser, it could shows you:<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><em>Warning: Unresponsive script\" prompt that says \"A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.\"<\/em><\/p>\n\n\n\n<p>It means that a script takes too long to run and the browser doesn\u2019t accept it.<\/p>\n\n\n\n<p>A consequence of it is that the user interaction with the browser and web page is stopped.<\/p>\n\n\n\n<p>The browser UI and JavaScript code share a single processing thread. Every event is added to a single queue. When the browser becomes idle, it retrieves the next event on the queue and executes it.<\/p>\n\n\n\n<p>In reality, browsers starts a new OS process for every tab. However, there is still a single event queue per viewed page and only one task can be completed at a time. This is necessary for rendering the web page and for the user interaction with the web page in the browser.<\/p>\n\n\n\n<p>To test the speed and limit of web browser in the execution of the JavaScript code we are going to use a heavy processing algorithm for generation of combinations without repetitions.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>DONALD KNUTH\u2019S ALGORITHM FOR GENERATION OF COMBINATIONS WITHOUT REPETITIONS<\/strong><\/p>\n\n\n\n<p> The number of combinations of n things, taken k at a time are exactly:<\/p>\n\n\n\n<p class=\"has-text-align-center\"> <img loading=\"lazy\" decoding=\"async\" width=\"81\" height=\"58\" class=\"wp-image-318\" style=\"width: 81px;\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/nk.png\" alt=\"\"><\/p>\n\n\n\n<p>We can think these n things as an ordered collection of objects and we can use binary notation to discover combinations.<\/p>\n\n\n\n<p>For example, we take a set of five letter: <span class=\"has-inline-color has-vivid-cyan-blue-color\">{A,B,C,D,E}<\/span> and we want to list the combinations of 2 letter from this set without repetitions. Using the formula above the number of combinations is 10.<\/p>\n\n\n\n<p>We consider this set as an ordered set: <span class=\"has-inline-color has-vivid-cyan-blue-color\">A&lt;B&lt;C&lt;D&lt;E<\/span> and we use the binary notation to represent it where<\/p>\n\n\n\n<p>0 means the letter is not in the combination and 1 means the letter is in the combination.<\/p>\n\n\n\n<p>We know that the number of all subsets is = 32 > 5, while we have to select of these subsets only those that have a number of elements equal to 2. <\/p>\n\n\n\n<p>Considering the set as an ordered set {A,B,C,D,E} and using the binary notation, the list of all subsets of this set are:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/Table.png\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"713\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/Table.png\" alt=\"\" class=\"wp-image-319\" srcset=\"https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/Table.png 658w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/Table-277x300.png 277w\" sizes=\"auto, (max-width: 658px) 100vw, 658px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>Only good binary representations are used to generate good combinations.<\/p>\n\n\n\n<p><a href=\"http:\/\/www.volucer.it\/zvaddon\/JSEngineTest.html\" data-type=\"URL\" data-id=\"http:\/\/www.volucer.it\/zvaddon\/JSEngineTest.html\" target=\"_blank\" rel=\"noreferrer noopener\">Here it is a combination tool<\/a>.<\/p>\n\n\n\n<p>A program in JavaScript to codify the algorithm could be:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>\/\/--------------------------------------------------------------------\nfunction <strong>GenerateCombination<\/strong>s()\n\t{\n\t  var Answer_Head = \"&lt;table border='1' >\";\n\t  var Answer_Body = \"\";\n\t  var Answer_Tail = \"&lt;\/table>\";\n\t  var ErrorCode = 0;\n\t  var ErrorMsg  = \"\";\n\n\t  var nCombSize = 0;\n\t  var BaseComb  = new Array();\n\t  var iBaseComb = 0;\n\t  var CodeComb  = 0;\n\t  var CombList  = new Array(); \n\t  var ACombItem = \"\";  \n\t  var BinaryNumber       = new Array();\n\t  var BinaryStringNumber = \"\";\n\t  var NProgres           = 0;\n\t  var RNProgres          = 0;\n          var NFilter            = 0;\n   \n          var Start = Date.now(); \n\t  var End = Date.now();\n\t  var Elapsed = End - Start \/\/ time in ms\t\n\t  var cElapsed = Elapsed.toString();\n\t\t    \n\t  \n\/\/ AREA INTELLIGENCE \n\t  \n  \/\/ Clear Area\n  window.document.getElementById(\"i_BackMsg\").innerHTML  = \"\" ;\n  window.document.getElementById(\"i_Answer\").innerHTML   = \"\"\n\t     \n\t\n\/\/ Check Input Data\n  if ( isNaN( window.document.getElementById(\"iN\").value) ) {  \n        ErrorCode = 1;\n       ErroMsg   = \"Attention !!! The Combination Size must be a number.\"; \n\t }\t \nelse {\n     if (window.document.getElementById(\"iN\").value == 0 || \n         window.document.getElementById(\"iN\").value == \"\" ) {\n    \t ErrorCode = 11;\n    \t ErroMsg = \"Attention !!! The Combination Size must be a value more then zero.\"; \n          }\n        else\n        {\n           if (window.document.getElementById(\"iN\").value >= 20 ) {\n              ErrorCode = 11;\n              ErroMsg   = \"Attention !!! The Combination Size must less then 20.\";\n            }\n\t    else\n\t    {             \t           \n\t      nCombSize = window.document.getElementById(\"iN\").value ;\n\t    };           \n\t};      \n\t};\n\n\/\/ Show Msg  \n  if ( ErrorCode > 0 ) {  \t       window.document.getElementById(\"i_BackMsg\").innerHTML =ErroMsg+\"&lt;br\/>\" ;\t  \nreturn;\n } \n  else\n {\n  window.document.getElementById(\"i_BackMsg\").innerHTML =\"OK!\" ;\n };\n\t  \n    \n    \n\/\/ Check Elements\n  iBaseComb = 0;\n        \n  if ( !(window.document.getElementById(\"i_e01\").value == \"\" || \n       window.document.getElementById(\"i_e01\").value == \"0\" )) {          \n              BaseComb&#91;iBaseComb]=window.document.getElementById(\"i_e01\").value;\n              iBaseComb++;\n  };      \n          \n         \n   <strong>&lt; .... ><\/strong>\n          \n        \nif ( !(window.document.getElementById(\"i_e20\").value == \"\" || \n      window.document.getElementById(\"i_e20\").value == \"0\" )) {          \n              BaseComb&#91;iBaseComb]=window.document.getElementById(\"i_e20\").value;\n              iBaseComb++;\n        };      \n\n\n     \n       if ( iBaseComb == 0 || iBaseComb &lt;= nCombSize )  {     \n    \t   ErrorCode = 11;\n    \t   ErroMsg = \"Attention !!! The Elements must not be equal to or more than the combination size.\";\t   \n       };\n       \n  \t  \/\/ Show Msg  \n    \t  if ( ErrorCode > 0 ) {\n    \t     window.document.getElementById(\"i_BackMsg\").innerHTML =ErroMsg+\"&lt;br\/>\" ;\t  \n    \t     return;\n    \t  } \n    \t  else\n    \t  {\n    \t      window.document.getElementById(\"i_BackMsg\").innerHTML = \"\" ;\n    \t  };       \n     \n     \n    \/\/ Combination Code\n       CodeComb=0;\n       for (j=0;j&lt;=iBaseComb-1;j++){\n           CodeComb+= Math.pow(2,j);\n       }; \n               \n\t\/\/ Combination Generator\n          CombList  = new Array(iBaseComb); \n       \n       for (y=0;y&lt;=CombList.length-1;y++){\n          CombList&#91;y]=\"0\"\n       };\n       RNProgress = 0;\n       NProgres   = 0;\n       for (k=0;k&lt;=(CodeComb); k++) {\n         \n            BinaryNumber = DecimalToBinary(k, iBaseComb);\n         \n                                 \n            if ( IsAGoodCombination (BinaryNumber, nCombSize ) ) {\n                    \n                  for (y=0;y&lt;=CombList.length-1;y++){\n                       CombList&#91;y]=\"0\";\n                   };                    \n                      \n                   \/\/ Make the combination       \n                   for (x=0;x&lt;=BinaryNumber.length-1;x++){                   \n                        \n                         if (BinaryNumber&#91;x]==\"1\"){\n                            CombList&#91;x]=BaseComb&#91;x];                                             \n                         };                         \n                                     \n                      };\n                      \n                     CombList.sort(function(a,b){return a - b});\n                      \n                     NProgres++;\n                     \n                      \n                     ACombItem=\"\";        \t\t\t\t\t  \n        for (j=0;j&lt;CombList.length;j++){\n\t\t\t \t\t     \n\t    if (CombList&#91;j]!=\"0\"){\t\t\t\t\t\t  \n               ACombItem=ACombItem+CombList&#91;j]+\" \";                                             \n             };                         \n\t};\n                     window.document.getElementById(\"i_Answer\").innerHTML+=NProgres.toString()+\" - \";\n window.document.getElementById(\"i_Answer\").innerHTML+=ACombItem+\"&lt;br \/>\";\n      };         \n };       \n window.document.getElementById(\"i_Answer\").innerHTML+=Answer_Tail+\"&lt;br \/>&lt;br \/>\";\n End = Date.now();\n Elapsed = End - Start \/\/ time in milliseconds\t\t\n cElapsed = Elapsed.toString();\n window.document.getElementById(\"i_Time\").innerHTML=\"Time Elapsed: \"+cElapsed+\" ms\";\n return ;\n}\n\t\n\/\/--------------------------------------------------------------------\nfunction <strong>DecimalToBinary<\/strong> (iDecNumber, iSize){\n  \n \/\/ Section Data Structure\n    answer = new Array(iSize);\n    n10  = iDecNumber;\n    x2   = iDecNumber;\n    log2 = 0;\n \/\/ Section Initialization \n    for (j=0; j&lt;=answer.length-1;j++){\n         answer&#91;j]=\"0\";\n    };          \n\/\/ Section Intelligence      \n    while (x2>=2) {\n          x2=x2\/2;\n          log2++;     \n    };\n     for (l2=log2;l2>=0;l2--) {\n       power = Math.pow(2,l2);\n       if (n10 >= power) {\n           answer&#91;l2]=\"1\";\n           n10 = n10 - power;\n       }\n       else {\n           answer&#91;l2]=\"0\";\n       };      \n     };     \n     answer.reverse();     \n     return answer     \n  }\n\t\n\/\/--------------------------------------------------------------------\n\t\nfunction <strong>IsAGoodCombination<\/strong> ( iBRNumber, iCombSize ) {        \n    var NumberOfOne = 0 ;\n    for (j=0;j&lt;=iBRNumber.length-1;j++) {        \n        if (iBRNumber&#91;j]==\"1\") {          \n          NumberOfOne++;          \n          if ( NumberOfOne >  iCombSize ) {\n             break;\n          };\n        };     \n    };    \n    if ( NumberOfOne == iCombSize ) {\n       return true; \n    }   \n    else {\n       return false;   \n    };\n  }  \n\/\/--------------------------------------------------------------------<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>WEB APPLICATION CLIENT-SIDE JAVASCRIPT PERFORMANCE<\/strong><\/p>\n\n\n\n<p>The results of using as benchmark the JavaScript program previously described are the following ones.<\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><a href=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table01.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"236\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table01-1024x236.png\" alt=\"\" data-id=\"326\" data-full-url=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table01.png\" data-link=\"http:\/\/www.volucer.it\/?attachment_id=326\" class=\"wp-image-326\" srcset=\"https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table01-1024x236.png 1024w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table01-300x69.png 300w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table01-768x177.png 768w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table01-960x221.png 960w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table01.png 1049w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/li><\/ul><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph01.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"526\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph01-1024x526.png\" alt=\"\" class=\"wp-image-328\" srcset=\"https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph01-1024x526.png 1024w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph01-300x154.png 300w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph01-768x394.png 768w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph01-960x493.png 960w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph01.png 1040w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph02.png\"><img loading=\"lazy\" decoding=\"async\" width=\"993\" height=\"607\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph02.png\" alt=\"\" class=\"wp-image-329\" srcset=\"https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph02.png 993w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph02-300x183.png 300w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph02-768x469.png 768w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph02-960x587.png 960w\" sizes=\"auto, (max-width: 993px) 100vw, 993px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table02.png\"><img loading=\"lazy\" decoding=\"async\" width=\"986\" height=\"271\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table02.png\" alt=\"\" class=\"wp-image-330\" srcset=\"https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table02.png 986w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table02-300x82.png 300w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table02-768x211.png 768w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Table02-960x264.png 960w\" sizes=\"auto, (max-width: 986px) 100vw, 986px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph03.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"521\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph03.png\" alt=\"\" class=\"wp-image-331\" srcset=\"https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph03.png 1004w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph03-300x156.png 300w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph03-768x399.png 768w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/03\/20210318_Graph03-960x498.png 960w\" sizes=\"auto, (max-width: 1004px) 100vw, 1004px\" \/><\/a><\/figure>\n\n\n\n<p>How we can see from the tables and graphs above SpiderMonkey Engine in this test result the winner.<\/p>\n\n\n\n<p>Only in the increase of execution time for high number of combinations it is not the best.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>REFERENCES<\/strong><\/p>\n\n\n\n<p><strong>[01]<\/strong> <em>Donald E. Knuth<\/em>, <strong>The Art of Computer Programming Volume 4 Generating All Combinations and Partitions Fascicle 3<\/strong>, July 2005;<\/p>\n\n\n\n<p><strong>[02]<\/strong> JavaScript Execution and Browser Limits <a href=\"https:\/\/www.sitepoint.com\/javascript-execution-browser-limits\/\">https:\/\/www.sitepoint.com\/javascript-execution-browser-limits\/<\/a> ;<\/p>\n\n\n\n<p><strong>[03]<\/strong> Web Browser <a href=\"http:\/\/www.volucer.it\/?p=143\">http:\/\/www.volucer.it\/?p=143<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JAVASCRIPT EXECUTION LIMITS IN THE WEB BROWSER When we ask the visualization of a web page in the browser, it could shows you: Warning: Unresponsive script\" prompt that says \"A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see <a class=\"read-more\" href=\"https:\/\/www.volucer.it\/?p=316\">...continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,7],"tags":[17],"class_list":["post-316","post","type-post","status-publish","format-standard","hentry","category-javascript-2","category-web-browser","tag-web-browser"],"_links":{"self":[{"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/posts\/316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.volucer.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=316"}],"version-history":[{"count":13,"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/posts\/316\/revisions"}],"predecessor-version":[{"id":337,"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/posts\/316\/revisions\/337"}],"wp:attachment":[{"href":"https:\/\/www.volucer.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.volucer.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.volucer.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}