{"id":69301,"date":"2016-12-23T15:09:11","date_gmt":"2016-12-23T15:09:11","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=69301"},"modified":"2016-12-26T10:12:00","modified_gmt":"2016-12-26T10:12:00","slug":"test-js-performance-browser","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/","title":{"rendered":"Test JS Performance with your own browser"},"content":{"rendered":"<p>We rarely need to test the performance of our written javascript and we need tools to\u00a0perform this process. We really don&#8217;t need any tool for making the performance test as our browser is a performance tester by itself. I wrote a little javascript in which the performance of our javascript can be tested to a level.<\/p>\n<p>Here&#8217;s the code:<\/p>\n<pre class=\"brush:js\">\/**\r\n * Webkul Software.\r\n *\r\n * @category Webkul\r\n * @package JS_Performance\r\n * @author Webkul\r\n * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\r\n * @license https:\/\/store.webkul.com\/license.html\r\n *\/\r\nvar performance_array = [];\r\nvar cycles = 10; \/\/ makes the average out of this number\r\nvar runs = 100; \/\/ number of times loop should process\r\n\r\nfunction function1() {\r\n\t\/\/ write your code here\r\n}\r\n\r\nfunction function2() {\r\n\t\/\/ write your code here\r\n}\r\n\r\nvar functions = ['function1', 'function2']; \/\/ Make an entry of the functions defined above\r\n\r\nfunctions.forEach(function (argument) {\r\n\tvar func = eval(\"argument\") + '();'; \/\/ manage the function to a variable\r\n\tvar timestamp = 0;\r\n\tfor (var i = 0; i &lt; cycles; i++) {\r\n\t\tvar pre = performance.now();\r\n\t\tfor (var j = 0; j &lt; runs; j++) {\r\n\t\t\teval(func); \/\/ runs the function\r\n\t\t}\r\n\t\tvar now = performance.now();\r\n\t\tvar time_in_cycle =  now - pre;\r\n\t\ttimestamp += time_in_cycle;\r\n\t}\r\n\tperformance_array[argument] = timestamp\/cycles;\r\n});\r\nconsole.log(performance_array);<\/pre>\n<p>This code can be used to make a test to some extent and to an accuracy but they are not totally accurate.<\/p>\n<p>I have used the code to make a test over, whether to get an element from its ID or traversing it from its parent. This code can give you an idea of how to use.<\/p>\n<pre class=\"brush:js\">&lt;!-- \r\n\/**\r\n * Webkul Software.\r\n *\r\n * @category Webkul\r\n * @package JS_Performance\r\n * @author Webkul\r\n * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\r\n * @license https:\/\/store.webkul.com\/license.html\r\n *\/\r\n --&gt;\r\n&lt;div&gt;\r\n\t&lt;button id=\"button\" onclick=\"calculate();\"&gt;button&lt;\/button&gt;\r\n&lt;\/div&gt;\r\n&lt;script type=\"text\/javascript\" src=\"jquery-2.1.1.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\nvar performance_array = [];\r\nvar cycles = 10; \/\/ makes the average out of this number\r\nvar runs = 100; \/\/ number of times loop should process\r\n\r\nfunction function1() {\r\n\t$('#button');\r\n}\r\n\r\nfunction function2() {\r\n\t$('div button');\r\n}\r\n\/\/ you can add more functions here\r\n\r\nvar functions = ['function1', 'function2']; \/\/ Make an entry of the functions defined above\r\n\r\nfunction calculate() {\r\n\tfunctions.forEach(function (argument) {\r\n\t\tvar func = eval(\"argument\") + '();'; \/\/ manage the function to a variable\r\n\t\tvar timestamp = 0;\r\n\t\tfor (var i = 0; i &lt; cycles; i++) {\r\n\t\t\tvar pre = performance.now();\r\n\t\t\tfor (var j = 0; j &lt; runs; j++) {\r\n\t\t\t\teval(func); \/\/ runs the function\r\n\t\t\t}\r\n\t\t\tvar now = performance.now();\r\n\t\t\tvar time_in_cycle =  now - pre;\r\n\t\t\ttimestamp += time_in_cycle;\r\n\t\t}\r\n\t\tperformance_array[argument] = timestamp\/cycles;\r\n\t});\r\n\tconsole.log(performance_array);\r\n}<\/pre>\n<p>Here, in this code, I&#8217;ve used the jQuery to get the element and for traverse down the child. This will give you an idea of the\u00a0performance of your code. Hope, it will help you out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We rarely need to test the performance of our written javascript and we need tools to\u00a0perform this process. We really don&#8217;t need any tool for making the performance test as our browser is a performance tester by itself. I wrote a little javascript in which the performance of our javascript can be tested to a <a href=\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":70,"featured_media":40972,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[198,79],"tags":[2064,1894,4247,4246],"class_list":["post-69301","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-jquery","tag-javascript","tag-js","tag-performance-tester","tag-profiler"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Test JS Performance with your own browser - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Test JS Performance with your own browser - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"We rarely need to test the performance of our written javascript and we need tools to\u00a0perform this process. We really don&#8217;t need any tool for making the performance test as our browser is a performance tester by itself. I wrote a little javascript in which the performance of our javascript can be tested to a [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-23T15:09:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-12-26T10:12:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vikhyat Sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vikhyat Sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/\"},\"author\":{\"name\":\"Vikhyat Sharma\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/af7160d2546c64a1856ab1b5ce77d9b0\"},\"headline\":\"Test JS Performance with your own browser\",\"datePublished\":\"2016-12-23T15:09:11+00:00\",\"dateModified\":\"2016-12-26T10:12:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/\"},\"wordCount\":160,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png\",\"keywords\":[\"JavaScript\",\"js\",\"performance tester\",\"profiler\"],\"articleSection\":[\"JavaScript\",\"jQuery\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/\",\"url\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/\",\"name\":\"Test JS Performance with your own browser - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png\",\"datePublished\":\"2016-12-23T15:09:11+00:00\",\"dateModified\":\"2016-12-26T10:12:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Test JS Performance with your own browser\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/af7160d2546c64a1856ab1b5ce77d9b0\",\"name\":\"Vikhyat Sharma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7c9c700cc2d7120c9faf1ab3392b4e533808ba197f58c0441d6caecc68179e12?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7c9c700cc2d7120c9faf1ab3392b4e533808ba197f58c0441d6caecc68179e12?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Vikhyat Sharma\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/vikhyat-sharma83\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Test JS Performance with your own browser - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/","og_locale":"en_US","og_type":"article","og_title":"Test JS Performance with your own browser - Webkul Blog","og_description":"We rarely need to test the performance of our written javascript and we need tools to\u00a0perform this process. We really don&#8217;t need any tool for making the performance test as our browser is a performance tester by itself. I wrote a little javascript in which the performance of our javascript can be tested to a [...]","og_url":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-12-23T15:09:11+00:00","article_modified_time":"2016-12-26T10:12:00+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png","type":"image\/png"}],"author":"Vikhyat Sharma","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Vikhyat Sharma","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/"},"author":{"name":"Vikhyat Sharma","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/af7160d2546c64a1856ab1b5ce77d9b0"},"headline":"Test JS Performance with your own browser","datePublished":"2016-12-23T15:09:11+00:00","dateModified":"2016-12-26T10:12:00+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/"},"wordCount":160,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png","keywords":["JavaScript","js","performance tester","profiler"],"articleSection":["JavaScript","jQuery"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/test-js-performance-browser\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/","url":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/","name":"Test JS Performance with your own browser - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png","datePublished":"2016-12-23T15:09:11+00:00","dateModified":"2016-12-26T10:12:00+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/test-js-performance-browser\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/02\/Code-Snippet.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/test-js-performance-browser\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Test JS Performance with your own browser"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/af7160d2546c64a1856ab1b5ce77d9b0","name":"Vikhyat Sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7c9c700cc2d7120c9faf1ab3392b4e533808ba197f58c0441d6caecc68179e12?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7c9c700cc2d7120c9faf1ab3392b4e533808ba197f58c0441d6caecc68179e12?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Vikhyat Sharma"},"url":"https:\/\/webkul.com\/blog\/author\/vikhyat-sharma83\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/70"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=69301"}],"version-history":[{"count":3,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69301\/revisions"}],"predecessor-version":[{"id":69383,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/69301\/revisions\/69383"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/40972"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=69301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=69301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=69301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}