0

I want to log the execution times of all my Javascript functions into a HTML5 local database (or use ajax to post the restults to the server), so I can find out which functions are the most time consuming and need to be tweaked.

I figured I should have some kind of 'base'-function that does this logging, on which I base all my other functions.

I know a little bit about prototype classes in Javascript, but obviously not enough. Are functions also some kind of objects that can be extended ?

Is it even possible to create this kind of base-function which starts a timer at the beginning of the function, and then after the extended function is finished then logs the execution time?

Dylan
  • 9,129
  • 20
  • 96
  • 153
  • Function.prototype.something adds something to all functions. if you want added functionality for existing functions, you need to rewrite or wrap them. return arguments.callee.apply(this, arguments); works transparently and generically without "use strict" in effect. – dandavis Sep 23 '13 at 16:09
  • No. Functions can be extended with methods via their prototype, but that won't help you to do logging when they are called. – Bergi Sep 23 '13 at 16:10
  • 2
    You should use the built-in profiler of your devtools, instead of impacting the behavior of the functions by doing additional logging. – Bergi Sep 23 '13 at 16:13
  • 1
    have a look [here](http://stackoverflow.com/questions/16759647/browser-console-and-calculating-multiple-javascript-execution-time-differences) and [here](http://stackoverflow.com/questions/313893/how-to-measure-time-taken-by-a-function-to-execute) – BeNdErR Sep 23 '13 at 16:15

0 Answers0