Javascript Function Profiler: Measure the time a function takes to execute

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 110 All time: 399 This week: 17Up
Version License JavaScript version Categories
function-profiler 1.0.0GNU General Publi...1.0Debug, Performance
Description 

Author

This object can measure the time a function takes to execute.

It takes a given function and calls it consecutively a given number of times.

The class returns the output of the function and the time that it took to execute the function in microseconds and milliseconds.

Innovation Award
JavaScript Programming Innovation award winner
July 2014
Winner
Sometimes it is necessary to optimize the performance of a given piece of JavaScript code.

This object allows to measure the time a function takes to execute many times, so you can evaluate more accurately if any optimizations have benefited the overall performance of the code of that function.

Manuel Lemos
Picture of Tony L. Requena
  Performance   Level  
Name: Tony L. Requena <contact>
Classes: 1 package by
Country: Spain Spain
Age: 42
All time rank: 1599 in Spain Spain
Week rank: 6 Up2 in Spain Spain Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Example

<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html" /> <meta name="author" content="Tony L. Requena" /> <title>Javascript Function Profiler :: Version 1.0.0</title> <script type="text/javascript" src="class.timeprofiler.js"></script> </head> <body> <h3>Performance Result</h3> <textarea style="width: 90%; height: 400px;" id="result"> Starting execution... </textarea> <script type="text/javascript"> function imprime($greeting, $friend){ return bin2hex($greeting+" "+$friend)+" -- "+$greeting+" "+$friend; } function blah($n){ if($n == undefined){ $n = 1; } for($i = 0; $i<= $n; $i++){ $a = $i; } } function bin2hex(s) { var i, l, o = '', n; s += ''; for (i = 0, l = s.length; i < l; i++) { n = s.charCodeAt(i) .toString(16); o += n.length < 2 ? '0' + n : n; } return o; } var $timer = new TimeProfiler('imprime',10,Array('hola','amigo')); var outputFunction = $timer.getMicro()+" µs ("+$timer.getMili()+" ms) Return: '"+$timer.funcOutput()+"'"; document.getElementById('result').innerHTML = outputFunction+"\n"; var $timer = new TimeProfiler('blah',10000); outputFunction = $timer.getMicro()+" µs ("+$timer.getMili()+" ms)"; document.getElementById('result').innerHTML = document.getElementById('result').innerHTML + outputFunction+"\n"; </script> </body> </html>

  Demo 01 class.timeprofiler.jsExternal page  

Open in a separate window

  Files folder image Files (2)  
File Role Description
Plain text file class.timeprofiler.js Class Main Class
Accessible without login Plain text file test.html Example Test File

 Version Control Unique User Downloads Download Rankings  
 0%
Total:110
This week:0
All time:399
This week:17Up