Best JavaScript code snippet using wpt
profiler-coverage.js
Source:profiler-coverage.js
1/*2YUI 3.7.3 (build 5687)3Copyright 2012 Yahoo! Inc. All rights reserved.4Licensed under the BSD License.5http://yuilibrary.com/license/6*/7if (typeof _yuitest_coverage == "undefined"){8 _yuitest_coverage = {};9 _yuitest_coverline = function(src, line){10 var coverage = _yuitest_coverage[src];11 if (!coverage.lines[line]){12 coverage.calledLines++;13 }14 coverage.lines[line]++;15 };16 _yuitest_coverfunc = function(src, name, line){17 var coverage = _yuitest_coverage[src],18 funcId = name + ":" + line;19 if (!coverage.functions[funcId]){20 coverage.calledFunctions++;21 }22 coverage.functions[funcId]++;23 };24}25_yuitest_coverage["build/profiler/profiler.js"] = {26 lines: {},27 functions: {},28 coveredLines: 0,29 calledLines: 0,30 coveredFunctions: 0,31 calledFunctions: 0,32 path: "build/profiler/profiler.js",33 code: []34};35_yuitest_coverage["build/profiler/profiler.js"].code=["YUI.add('profiler', function (Y, NAME) {",""," /**"," * The YUI JavaScript profiler."," * @module profiler"," */"," "," //-------------------------------------------------------------------------"," // Private Variables and Functions"," //-------------------------------------------------------------------------"," "," var container = {}, //Container object on which to put the original unprofiled methods."," report = {}, //Profiling information for functions"," stopwatches = {}, //Additional stopwatch information"," "," WATCH_STARTED = 0,"," WATCH_STOPPED = 1,"," WATCH_PAUSED = 2, "," "," //shortcuts"," L = Y.Lang;",""," /* (intentionally not documented)"," * Creates a report object with the given name."," * @param {String} name The name to store for the report object."," * @return {Void}"," * @method createReport"," * @private"," */"," function createReport(name){"," report[name] = {"," calls: 0,"," max: 0,"," min: 0,"," avg: 0,"," points: []"," };"," return report[name];"," }"," "," /* (intentionally not documented)"," * Called when a method ends execution. Marks the start and end time of the "," * method so it can calculate how long the function took to execute. Also "," * updates min/max/avg calculations for the function."," * @param {String} name The name of the function to mark as stopped."," * @param {int} duration The number of milliseconds it took the function to"," * execute."," * @return {Void}"," * @method saveDataPoint"," * @private"," * @static"," */"," function saveDataPoint(name, duration){",""," //get the function data"," var functionData /*:Object*/ = report[name];"," "," //just in case clear() was called"," if (!functionData){"," functionData = createReport(name);"," }"," "," //increment the calls"," functionData.calls++;"," functionData.points.push(duration);",""," //if it's already been called at least once, do more complex calculations"," if (functionData.calls > 1) {"," functionData.avg = ((functionData.avg*(functionData.calls-1))+duration)/functionData.calls;"," functionData.min = Math.min(functionData.min, duration);"," functionData.max = Math.max(functionData.max, duration);"," } else {"," functionData.avg = duration;"," functionData.min = duration;"," functionData.max = duration;"," } "," "," }"," "," //-------------------------------------------------------------------------"," // Public Interface"," //-------------------------------------------------------------------------"," "," /**"," * Profiles functions in JavaScript."," * @class Profiler"," * @static"," */"," Y.Profiler = {"," "," //-------------------------------------------------------------------------"," // Utility Methods"," //------------------------------------------------------------------------- "," "," /**"," * Removes all report data from the profiler."," * @param {String} name (Optional) The name of the report to clear. If"," * omitted, then all report data is cleared."," * @return {Void}"," * @method clear"," * @static"," */"," clear: function(name){"," if (L.isString(name)){"," delete report[name];"," delete stopwatches[name];"," } else {"," report = {};"," stopwatches = {};"," }"," },",""," /**"," * Returns the uninstrumented version of a function/object."," * @param {String} name The name of the function/object to retrieve."," * @return {Function|Object} The uninstrumented version of a function/object."," * @method getOriginal"," * @static"," */ "," getOriginal: function(name){"," return container[name];"," },"," "," /**"," * Instruments a method to have profiling calls."," * @param {String} name The name of the report for the function."," * @param {Function} method The function to instrument."," * @return {Function} An instrumented version of the function."," * @method instrument"," * @static"," */"," instrument: function(name, method){"," "," //create instrumented version of function"," var newMethod = function () {"," "," var start = new Date(),"," retval = method.apply(this, arguments),"," stop = new Date();"," "," saveDataPoint(name, stop-start);"," "," return retval; "," "," }; ",""," //copy the function properties over"," Y.mix(newMethod, method);"," "," //assign prototype and flag as being profiled"," newMethod.__yuiProfiled = true;"," newMethod.prototype = method.prototype;"," "," //store original method"," container[name] = method;"," container[name].__yuiFuncName = name;"," "," //create the report"," createReport(name);",""," //return the new method"," return newMethod;"," }, "," "," //-------------------------------------------------------------------------"," // Stopwatch Methods"," //------------------------------------------------------------------------- "," "," /**"," * Pauses profiling information for a given name."," * @param {String} name The name of the data point."," * @return {Void}"," * @method pause"," * @static"," */ "," pause: function(name){"," var now = new Date(),"," stopwatch = stopwatches[name];"," "," if (stopwatch && stopwatch.state == WATCH_STARTED){"," stopwatch.total += (now - stopwatch.start);"," stopwatch.start = 0;"," stopwatch.state = WATCH_PAUSED;"," }"," "," },"," "," /**"," * Start profiling information for a given name. The name cannot be the name"," * of a registered function or object. This is used to start timing for a"," * particular block of code rather than instrumenting the entire function."," * @param {String} name The name of the data point."," * @return {Void}"," * @method start"," * @static"," */"," start: function(name){"," if(container[name]){"," throw new Error(\"Cannot use '\" + name + \"' for profiling through start(), name is already in use.\");"," } else {"," "," //create report if necessary"," if (!report[name]){"," createReport(name);"," }"," "," //create stopwatch object if necessary"," if (!stopwatches[name]){ "," stopwatches[name] = {"," state: WATCH_STOPPED,"," start: 0,"," total: 0"," };"," }"," "," if (stopwatches[name].state == WATCH_STOPPED){"," stopwatches[name].state = WATCH_STARTED;"," stopwatches[name].start = new Date(); "," }",""," }"," },"," "," /**"," * Stops profiling information for a given name."," * @param {String} name The name of the data point."," * @return {Void}"," * @method stop"," * @static"," */"," stop: function(name){"," var now = new Date(),"," stopwatch = stopwatches[name];"," "," if (stopwatch){"," if (stopwatch.state == WATCH_STARTED){"," saveDataPoint(name, stopwatch.total + (now - stopwatch.start)); "," } else if (stopwatch.state == WATCH_PAUSED){"," saveDataPoint(name, stopwatch.total);"," }"," "," //reset stopwatch information"," stopwatch.start = 0;"," stopwatch.total = 0;"," stopwatch.state = WATCH_STOPPED; "," }"," },"," "," //-------------------------------------------------------------------------"," // Reporting Methods"," //------------------------------------------------------------------------- "," "," /**"," * Returns the average amount of time (in milliseconds) that the function"," * with the given name takes to execute."," * @param {String} name The name of the function whose data should be returned."," * If an object type method, it should be 'constructor.prototype.methodName';"," * a normal object method would just be 'object.methodName'."," * @return {float} The average time it takes the function to execute."," * @method getAverage"," * @static"," */"," getAverage : function (name /*:String*/) /*:float*/ {"," return report[name].avg;"," },"," "," /**"," * Returns the number of times that the given function has been called."," * @param {String} name The name of the function whose data should be returned."," * @return {int} The number of times the function was called."," * @method getCallCount"," * @static"," */"," getCallCount : function (name /*:String*/) /*:int*/ {"," return report[name].calls; "," },"," "," /**"," * Returns the maximum amount of time (in milliseconds) that the function"," * with the given name takes to execute."," * @param {String} name The name of the function whose data should be returned."," * If an object type method, it should be 'constructor.prototype.methodName';"," * a normal object method would just be 'object.methodName'."," * @return {float} The maximum time it takes the function to execute."," * @method getMax"," * @static"," */"," getMax : function (name /*:String*/) /*:int*/ {"," return report[name].max;"," },"," "," /**"," * Returns the minimum amount of time (in milliseconds) that the function"," * with the given name takes to execute."," * @param {String} name The name of the function whose data should be returned."," * If an object type method, it should be 'constructor.prototype.methodName';"," * a normal object method would just be 'object.methodName'."," * @return {float} The minimum time it takes the function to execute."," * @method getMin"," * @static"," */"," getMin : function (name /*:String*/) /*:int*/ {"," return report[name].min;"," },"," "," /**"," * Returns an object containing profiling data for a single function."," * The object has an entry for min, max, avg, calls, and points)."," * @return {Object} An object containing profile data for a given function."," * @method getFunctionReport"," * @static"," * @deprecated Use getReport() instead."," */"," getFunctionReport : function (name /*:String*/) /*:Object*/ {"," return report[name];"," },"," "," /**"," * Returns an object containing profiling data for a single function."," * The object has an entry for min, max, avg, calls, and points)."," * @return {Object} An object containing profile data for a given function."," * @method getReport"," * @static"," */"," getReport : function (name /*:String*/) /*:Object*/ {"," return report[name];"," },"," "," /**"," * Returns an object containing profiling data for all of the functions "," * that were profiled. The object has an entry for each function and "," * returns all information (min, max, average, calls, etc.) for each"," * function."," * @return {Object} An object containing all profile data."," * @method getFullReport"," * @static"," */"," getFullReport : function (filter /*:Function*/) /*:Object*/ {"," filter = filter || function(){return true;};"," "," if (L.isFunction(filter)) {"," var fullReport = {};"," "," for (var name in report){"," if (filter(report[name])){"," fullReport[name] = report[name]; "," }"," }"," "," return fullReport;"," }"," },"," "," //-------------------------------------------------------------------------"," // Profiling Methods"," //------------------------------------------------------------------------- "," "," /**"," * Sets up a constructor for profiling, including all properties and methods on the prototype."," * @param {string} name The fully-qualified name of the function including namespace information."," * @param {Object} owner (Optional) The object that owns the function (namespace or containing object)."," * @return {Void}"," * @method registerConstructor"," * @static"," */"," registerConstructor : function (name /*:String*/, owner /*:Object*/) /*:Void*/ { "," this.registerFunction(name, owner, true);"," },"," "," /**"," * Sets up a function for profiling. It essentially overwrites the function with one"," * that has instrumentation data. This method also creates an entry for the function"," * in the profile report. The original function is stored on the container object."," * @param {String} name The full name of the function including namespacing. This"," * is the name of the function that is stored in the report."," * @param {Object} owner (Optional) The object that owns the function. If the function"," * isn't global then this argument is required. This could be the namespace that"," * the function belongs to or the object on which it's"," * a method."," * @param {Boolean} registerPrototype (Optional) Indicates that the prototype should"," * also be instrumented. Setting to true has the same effect as calling"," * registerConstructor()."," * @return {Void}"," * @method registerFunction"," * @static"," */ "," registerFunction : function(name /*:String*/, owner /*:Object*/, registerPrototype /*:Boolean*/) /*:Void*/{"," "," //figure out the function name without namespacing"," var funcName = (name.indexOf(\".\") > -1 ? "," name.substring(name.lastIndexOf(\".\")+1) : name),"," method,"," prototype;"," "," //if owner isn't an object, try to find it from the name"," if (!L.isObject(owner)){"," owner = eval(name.substring(0, name.lastIndexOf(\".\")));"," }"," "," //get the method and prototype"," method = owner[funcName];"," prototype = method.prototype;"," "," //see if the method has already been registered"," if (L.isFunction(method) && !method.__yuiProfiled){"," "," //replace the function with the profiling one"," owner[funcName] = this.instrument(name, method);"," "," /*"," * Store original function information. We store the actual"," * function as well as the owner and the name used to identify"," * the function so it can be restored later."," */"," container[name].__yuiOwner = owner;"," container[name].__yuiFuncName = funcName; //overwrite with less-specific name"," "," //register prototype if necessary"," if (registerPrototype) { "," this.registerObject(name + \".prototype\", prototype); "," }"," "," }"," "," },"," "," "," /**"," * Sets up an object for profiling. It takes the object and looks for functions."," * When a function is found, registerMethod() is called on it. If set to recrusive"," * mode, it will also setup objects found inside of this object for profiling, "," * using the same methodology."," * @param {String} name The name of the object to profile (shows up in report)."," * @param {Object} owner (Optional) The object represented by the name."," * @param {Boolean} recurse (Optional) Determines if subobject methods are also profiled."," * @return {Void}"," * @method registerObject"," * @static"," */"," registerObject : function (name /*:String*/, object /*:Object*/, recurse /*:Boolean*/) /*:Void*/{"," "," //get the object"," object = (L.isObject(object) ? object : eval(name));"," "," //save the object"," container[name] = object;"," "," for (var prop in object) {"," if (typeof object[prop] == \"function\"){"," if (prop != \"constructor\" && prop != \"superclass\"){ //don't do constructor or superclass, it's recursive"," this.registerFunction(name + \".\" + prop, object);"," }"," } else if (typeof object[prop] == \"object\" && recurse){"," this.registerObject(name + \".\" + prop, object[prop], recurse);"," }"," }"," "," }, "," "," /**"," * Removes a constructor function from profiling. Reverses the registerConstructor() method."," * @param {String} name The full name of the function including namespacing. This"," * is the name of the function that is stored in the report."," * @return {Void}"," * @method unregisterFunction"," * @static"," */ "," unregisterConstructor : function(name /*:String*/) /*:Void*/{"," "," //see if the method has been registered"," if (L.isFunction(container[name])){"," this.unregisterFunction(name, true);"," } "," },"," "," /**"," * Removes function from profiling. Reverses the registerFunction() method."," * @param {String} name The full name of the function including namespacing. This"," * is the name of the function that is stored in the report."," * @return {Void}"," * @method unregisterFunction"," * @static"," */ "," unregisterFunction : function(name /*:String*/, unregisterPrototype /*:Boolean*/) /*:Void*/{"," "," //see if the method has been registered"," if (L.isFunction(container[name])){"," "," //check to see if you should unregister the prototype"," if (unregisterPrototype){"," this.unregisterObject(name + \".prototype\", container[name].prototype);"," }"," "," //get original data"," var owner /*:Object*/ = container[name].__yuiOwner,"," funcName /*:String*/ = container[name].__yuiFuncName;"," "," //delete extra information"," delete container[name].__yuiOwner;"," delete container[name].__yuiFuncName;"," "," //replace instrumented function"," owner[funcName] = container[name];"," "," //delete supporting information"," delete container[name]; "," }"," "," "," },"," "," /**"," * Unregisters an object for profiling. It takes the object and looks for functions."," * When a function is found, unregisterMethod() is called on it. If set to recrusive"," * mode, it will also unregister objects found inside of this object, "," * using the same methodology."," * @param {String} name The name of the object to unregister."," * @param {Boolean} recurse (Optional) Determines if subobject methods should also be"," * unregistered."," * @return {Void}"," * @method unregisterObject"," * @static"," */"," unregisterObject : function (name /*:String*/, recurse /*:Boolean*/) /*:Void*/{"," "," //get the object"," if (L.isObject(container[name])){ "," var object = container[name]; "," "," for (var prop in object) {"," if (typeof object[prop] == \"function\"){"," this.unregisterFunction(name + \".\" + prop);"," } else if (typeof object[prop] == \"object\" && recurse){"," this.unregisterObject(name + \".\" + prop, recurse);"," }"," }"," "," delete container[name];"," }"," "," }"," "," "," };","","}, '3.7.3', {\"requires\": [\"yui-base\"]});"];36_yuitest_coverage["build/profiler/profiler.js"].lines = {"1":0,"12":0,"30":0,"31":0,"38":0,"53":0,"56":0,"59":0,"60":0,"64":0,"65":0,"68":0,"69":0,"70":0,"71":0,"73":0,"74":0,"75":0,"89":0,"104":0,"105":0,"106":0,"108":0,"109":0,"121":0,"135":0,"137":0,"141":0,"143":0,"148":0,"151":0,"152":0,"155":0,"156":0,"159":0,"162":0,"177":0,"180":0,"181":0,"182":0,"183":0,"198":0,"199":0,"203":0,"204":0,"208":0,"209":0,"216":0,"217":0,"218":0,"232":0,"235":0,"236":0,"237":0,"238":0,"239":0,"243":0,"244":0,"245":0,"264":0,"275":0,"289":0,"303":0,"315":0,"326":0,"339":0,"341":0,"342":0,"344":0,"345":0,"346":0,"350":0,"367":0,"390":0,"396":0,"397":0,"401":0,"402":0,"405":0,"408":0,"415":0,"416":0,"419":0,"420":0,"443":0,"446":0,"448":0,"449":0,"450":0,"451":0,"453":0,"454":0,"471":0,"472":0,"487":0,"490":0,"491":0,"495":0,"499":0,"500":0,"503":0,"506":0,"527":0,"528":0,"530":0,"531":0,"532":0,"533":0,"534":0,"538":0};37_yuitest_coverage["build/profiler/profiler.js"].functions = {"createReport:30":0,"saveDataPoint:53":0,"clear:103":0,"getOriginal:120":0,"newMethod:135":0,"instrument:132":0,"pause:176":0,"start:197":0,"stop:231":0,"getAverage:263":0,"getCallCount:274":0,"getMax:288":0,"getMin:302":0,"getFunctionReport:314":0,"getReport:325":0,"(anonymous 2):339":0,"getFullReport:338":0,"registerConstructor:366":0,"registerFunction:387":0,"registerObject:440":0,"unregisterConstructor:468":0,"unregisterFunction:484":0,"unregisterObject:524":0,"(anonymous 1):1":0};38_yuitest_coverage["build/profiler/profiler.js"].coveredLines = 110;39_yuitest_coverage["build/profiler/profiler.js"].coveredFunctions = 24;40_yuitest_coverline("build/profiler/profiler.js", 1);41YUI.add('profiler', function (Y, NAME) {42 /**43 * The YUI JavaScript profiler.44 * @module profiler45 */46 47 //-------------------------------------------------------------------------48 // Private Variables and Functions49 //-------------------------------------------------------------------------50 51 _yuitest_coverfunc("build/profiler/profiler.js", "(anonymous 1)", 1);52_yuitest_coverline("build/profiler/profiler.js", 12);53var container = {}, //Container object on which to put the original unprofiled methods.54 report = {}, //Profiling information for functions55 stopwatches = {}, //Additional stopwatch information56 57 WATCH_STARTED = 0,58 WATCH_STOPPED = 1,59 WATCH_PAUSED = 2, 60 61 //shortcuts62 L = Y.Lang;63 /* (intentionally not documented)64 * Creates a report object with the given name.65 * @param {String} name The name to store for the report object.66 * @return {Void}67 * @method createReport68 * @private69 */70 _yuitest_coverline("build/profiler/profiler.js", 30);71function createReport(name){72 _yuitest_coverfunc("build/profiler/profiler.js", "createReport", 30);73_yuitest_coverline("build/profiler/profiler.js", 31);74report[name] = {75 calls: 0,76 max: 0,77 min: 0,78 avg: 0,79 points: []80 };81 _yuitest_coverline("build/profiler/profiler.js", 38);82return report[name];83 }84 85 /* (intentionally not documented)86 * Called when a method ends execution. Marks the start and end time of the 87 * method so it can calculate how long the function took to execute. Also 88 * updates min/max/avg calculations for the function.89 * @param {String} name The name of the function to mark as stopped.90 * @param {int} duration The number of milliseconds it took the function to91 * execute.92 * @return {Void}93 * @method saveDataPoint94 * @private95 * @static96 */97 _yuitest_coverline("build/profiler/profiler.js", 53);98function saveDataPoint(name, duration){99 //get the function data100 _yuitest_coverfunc("build/profiler/profiler.js", "saveDataPoint", 53);101_yuitest_coverline("build/profiler/profiler.js", 56);102var functionData /*:Object*/ = report[name];103 104 //just in case clear() was called105 _yuitest_coverline("build/profiler/profiler.js", 59);106if (!functionData){107 _yuitest_coverline("build/profiler/profiler.js", 60);108functionData = createReport(name);109 }110 111 //increment the calls112 _yuitest_coverline("build/profiler/profiler.js", 64);113functionData.calls++;114 _yuitest_coverline("build/profiler/profiler.js", 65);115functionData.points.push(duration);116 //if it's already been called at least once, do more complex calculations117 _yuitest_coverline("build/profiler/profiler.js", 68);118if (functionData.calls > 1) {119 _yuitest_coverline("build/profiler/profiler.js", 69);120functionData.avg = ((functionData.avg*(functionData.calls-1))+duration)/functionData.calls;121 _yuitest_coverline("build/profiler/profiler.js", 70);122functionData.min = Math.min(functionData.min, duration);123 _yuitest_coverline("build/profiler/profiler.js", 71);124functionData.max = Math.max(functionData.max, duration);125 } else {126 _yuitest_coverline("build/profiler/profiler.js", 73);127functionData.avg = duration;128 _yuitest_coverline("build/profiler/profiler.js", 74);129functionData.min = duration;130 _yuitest_coverline("build/profiler/profiler.js", 75);131functionData.max = duration;132 } 133 134 }135 136 //-------------------------------------------------------------------------137 // Public Interface138 //-------------------------------------------------------------------------139 140 /**141 * Profiles functions in JavaScript.142 * @class Profiler143 * @static144 */145 _yuitest_coverline("build/profiler/profiler.js", 89);146Y.Profiler = {147 148 //-------------------------------------------------------------------------149 // Utility Methods150 //------------------------------------------------------------------------- 151 152 /**153 * Removes all report data from the profiler.154 * @param {String} name (Optional) The name of the report to clear. If155 * omitted, then all report data is cleared.156 * @return {Void}157 * @method clear158 * @static159 */160 clear: function(name){161 _yuitest_coverfunc("build/profiler/profiler.js", "clear", 103);162_yuitest_coverline("build/profiler/profiler.js", 104);163if (L.isString(name)){164 _yuitest_coverline("build/profiler/profiler.js", 105);165delete report[name];166 _yuitest_coverline("build/profiler/profiler.js", 106);167delete stopwatches[name];168 } else {169 _yuitest_coverline("build/profiler/profiler.js", 108);170report = {};171 _yuitest_coverline("build/profiler/profiler.js", 109);172stopwatches = {};173 }174 },175 /**176 * Returns the uninstrumented version of a function/object.177 * @param {String} name The name of the function/object to retrieve.178 * @return {Function|Object} The uninstrumented version of a function/object.179 * @method getOriginal180 * @static181 */ 182 getOriginal: function(name){183 _yuitest_coverfunc("build/profiler/profiler.js", "getOriginal", 120);184_yuitest_coverline("build/profiler/profiler.js", 121);185return container[name];186 },187 188 /**189 * Instruments a method to have profiling calls.190 * @param {String} name The name of the report for the function.191 * @param {Function} method The function to instrument.192 * @return {Function} An instrumented version of the function.193 * @method instrument194 * @static195 */196 instrument: function(name, method){197 198 //create instrumented version of function199 _yuitest_coverfunc("build/profiler/profiler.js", "instrument", 132);200_yuitest_coverline("build/profiler/profiler.js", 135);201var newMethod = function () {202 203 _yuitest_coverfunc("build/profiler/profiler.js", "newMethod", 135);204_yuitest_coverline("build/profiler/profiler.js", 137);205var start = new Date(),206 retval = method.apply(this, arguments),207 stop = new Date();208 209 _yuitest_coverline("build/profiler/profiler.js", 141);210saveDataPoint(name, stop-start);211 212 _yuitest_coverline("build/profiler/profiler.js", 143);213return retval; 214 215 }; 216 //copy the function properties over217 _yuitest_coverline("build/profiler/profiler.js", 148);218Y.mix(newMethod, method);219 220 //assign prototype and flag as being profiled221 _yuitest_coverline("build/profiler/profiler.js", 151);222newMethod.__yuiProfiled = true;223 _yuitest_coverline("build/profiler/profiler.js", 152);224newMethod.prototype = method.prototype;225 226 //store original method227 _yuitest_coverline("build/profiler/profiler.js", 155);228container[name] = method;229 _yuitest_coverline("build/profiler/profiler.js", 156);230container[name].__yuiFuncName = name;231 232 //create the report233 _yuitest_coverline("build/profiler/profiler.js", 159);234createReport(name);235 //return the new method236 _yuitest_coverline("build/profiler/profiler.js", 162);237return newMethod;238 }, 239 240 //-------------------------------------------------------------------------241 // Stopwatch Methods242 //------------------------------------------------------------------------- 243 244 /**245 * Pauses profiling information for a given name.246 * @param {String} name The name of the data point.247 * @return {Void}248 * @method pause249 * @static250 */ 251 pause: function(name){252 _yuitest_coverfunc("build/profiler/profiler.js", "pause", 176);253_yuitest_coverline("build/profiler/profiler.js", 177);254var now = new Date(),255 stopwatch = stopwatches[name];256 257 _yuitest_coverline("build/profiler/profiler.js", 180);258if (stopwatch && stopwatch.state == WATCH_STARTED){259 _yuitest_coverline("build/profiler/profiler.js", 181);260stopwatch.total += (now - stopwatch.start);261 _yuitest_coverline("build/profiler/profiler.js", 182);262stopwatch.start = 0;263 _yuitest_coverline("build/profiler/profiler.js", 183);264stopwatch.state = WATCH_PAUSED;265 }266 267 },268 269 /**270 * Start profiling information for a given name. The name cannot be the name271 * of a registered function or object. This is used to start timing for a272 * particular block of code rather than instrumenting the entire function.273 * @param {String} name The name of the data point.274 * @return {Void}275 * @method start276 * @static277 */278 start: function(name){279 _yuitest_coverfunc("build/profiler/profiler.js", "start", 197);280_yuitest_coverline("build/profiler/profiler.js", 198);281if(container[name]){282 _yuitest_coverline("build/profiler/profiler.js", 199);283throw new Error("Cannot use '" + name + "' for profiling through start(), name is already in use.");284 } else {285 286 //create report if necessary287 _yuitest_coverline("build/profiler/profiler.js", 203);288if (!report[name]){289 _yuitest_coverline("build/profiler/profiler.js", 204);290createReport(name);291 }292 293 //create stopwatch object if necessary294 _yuitest_coverline("build/profiler/profiler.js", 208);295if (!stopwatches[name]){ 296 _yuitest_coverline("build/profiler/profiler.js", 209);297stopwatches[name] = {298 state: WATCH_STOPPED,299 start: 0,300 total: 0301 };302 }303 304 _yuitest_coverline("build/profiler/profiler.js", 216);305if (stopwatches[name].state == WATCH_STOPPED){306 _yuitest_coverline("build/profiler/profiler.js", 217);307stopwatches[name].state = WATCH_STARTED;308 _yuitest_coverline("build/profiler/profiler.js", 218);309stopwatches[name].start = new Date(); 310 }311 }312 },313 314 /**315 * Stops profiling information for a given name.316 * @param {String} name The name of the data point.317 * @return {Void}318 * @method stop319 * @static320 */321 stop: function(name){322 _yuitest_coverfunc("build/profiler/profiler.js", "stop", 231);323_yuitest_coverline("build/profiler/profiler.js", 232);324var now = new Date(),325 stopwatch = stopwatches[name];326 327 _yuitest_coverline("build/profiler/profiler.js", 235);328if (stopwatch){329 _yuitest_coverline("build/profiler/profiler.js", 236);330if (stopwatch.state == WATCH_STARTED){331 _yuitest_coverline("build/profiler/profiler.js", 237);332saveDataPoint(name, stopwatch.total + (now - stopwatch.start)); 333 } else {_yuitest_coverline("build/profiler/profiler.js", 238);334if (stopwatch.state == WATCH_PAUSED){335 _yuitest_coverline("build/profiler/profiler.js", 239);336saveDataPoint(name, stopwatch.total);337 }}338 339 //reset stopwatch information340 _yuitest_coverline("build/profiler/profiler.js", 243);341stopwatch.start = 0;342 _yuitest_coverline("build/profiler/profiler.js", 244);343stopwatch.total = 0;344 _yuitest_coverline("build/profiler/profiler.js", 245);345stopwatch.state = WATCH_STOPPED; 346 }347 },348 349 //-------------------------------------------------------------------------350 // Reporting Methods351 //------------------------------------------------------------------------- 352 353 /**354 * Returns the average amount of time (in milliseconds) that the function355 * with the given name takes to execute.356 * @param {String} name The name of the function whose data should be returned.357 * If an object type method, it should be 'constructor.prototype.methodName';358 * a normal object method would just be 'object.methodName'.359 * @return {float} The average time it takes the function to execute.360 * @method getAverage361 * @static362 */363 getAverage : function (name /*:String*/) /*:float*/ {364 _yuitest_coverfunc("build/profiler/profiler.js", "getAverage", 263);365_yuitest_coverline("build/profiler/profiler.js", 264);366return report[name].avg;367 },368 369 /**370 * Returns the number of times that the given function has been called.371 * @param {String} name The name of the function whose data should be returned.372 * @return {int} The number of times the function was called.373 * @method getCallCount374 * @static375 */376 getCallCount : function (name /*:String*/) /*:int*/ {377 _yuitest_coverfunc("build/profiler/profiler.js", "getCallCount", 274);378_yuitest_coverline("build/profiler/profiler.js", 275);379return report[name].calls; 380 },381 382 /**383 * Returns the maximum amount of time (in milliseconds) that the function384 * with the given name takes to execute.385 * @param {String} name The name of the function whose data should be returned.386 * If an object type method, it should be 'constructor.prototype.methodName';387 * a normal object method would just be 'object.methodName'.388 * @return {float} The maximum time it takes the function to execute.389 * @method getMax390 * @static391 */392 getMax : function (name /*:String*/) /*:int*/ {393 _yuitest_coverfunc("build/profiler/profiler.js", "getMax", 288);394_yuitest_coverline("build/profiler/profiler.js", 289);395return report[name].max;396 },397 398 /**399 * Returns the minimum amount of time (in milliseconds) that the function400 * with the given name takes to execute.401 * @param {String} name The name of the function whose data should be returned.402 * If an object type method, it should be 'constructor.prototype.methodName';403 * a normal object method would just be 'object.methodName'.404 * @return {float} The minimum time it takes the function to execute.405 * @method getMin406 * @static407 */408 getMin : function (name /*:String*/) /*:int*/ {409 _yuitest_coverfunc("build/profiler/profiler.js", "getMin", 302);410_yuitest_coverline("build/profiler/profiler.js", 303);411return report[name].min;412 },413 414 /**415 * Returns an object containing profiling data for a single function.416 * The object has an entry for min, max, avg, calls, and points).417 * @return {Object} An object containing profile data for a given function.418 * @method getFunctionReport419 * @static420 * @deprecated Use getReport() instead.421 */422 getFunctionReport : function (name /*:String*/) /*:Object*/ {423 _yuitest_coverfunc("build/profiler/profiler.js", "getFunctionReport", 314);424_yuitest_coverline("build/profiler/profiler.js", 315);425return report[name];426 },427 428 /**429 * Returns an object containing profiling data for a single function.430 * The object has an entry for min, max, avg, calls, and points).431 * @return {Object} An object containing profile data for a given function.432 * @method getReport433 * @static434 */435 getReport : function (name /*:String*/) /*:Object*/ {436 _yuitest_coverfunc("build/profiler/profiler.js", "getReport", 325);437_yuitest_coverline("build/profiler/profiler.js", 326);438return report[name];439 },440 441 /**442 * Returns an object containing profiling data for all of the functions 443 * that were profiled. The object has an entry for each function and 444 * returns all information (min, max, average, calls, etc.) for each445 * function.446 * @return {Object} An object containing all profile data.447 * @method getFullReport448 * @static449 */450 getFullReport : function (filter /*:Function*/) /*:Object*/ {451 _yuitest_coverfunc("build/profiler/profiler.js", "getFullReport", 338);452_yuitest_coverline("build/profiler/profiler.js", 339);453filter = filter || function(){_yuitest_coverfunc("build/profiler/profiler.js", "(anonymous 2)", 339);454return true;};455 456 _yuitest_coverline("build/profiler/profiler.js", 341);457if (L.isFunction(filter)) {458 _yuitest_coverline("build/profiler/profiler.js", 342);459var fullReport = {};460 461 _yuitest_coverline("build/profiler/profiler.js", 344);462for (var name in report){463 _yuitest_coverline("build/profiler/profiler.js", 345);464if (filter(report[name])){465 _yuitest_coverline("build/profiler/profiler.js", 346);466fullReport[name] = report[name]; 467 }468 }469 470 _yuitest_coverline("build/profiler/profiler.js", 350);471return fullReport;472 }473 },474 475 //-------------------------------------------------------------------------476 // Profiling Methods477 //------------------------------------------------------------------------- 478 479 /**480 * Sets up a constructor for profiling, including all properties and methods on the prototype.481 * @param {string} name The fully-qualified name of the function including namespace information.482 * @param {Object} owner (Optional) The object that owns the function (namespace or containing object).483 * @return {Void}484 * @method registerConstructor485 * @static486 */487 registerConstructor : function (name /*:String*/, owner /*:Object*/) /*:Void*/ { 488 _yuitest_coverfunc("build/profiler/profiler.js", "registerConstructor", 366);489_yuitest_coverline("build/profiler/profiler.js", 367);490this.registerFunction(name, owner, true);491 },492 493 /**494 * Sets up a function for profiling. It essentially overwrites the function with one495 * that has instrumentation data. This method also creates an entry for the function496 * in the profile report. The original function is stored on the container object.497 * @param {String} name The full name of the function including namespacing. This498 * is the name of the function that is stored in the report.499 * @param {Object} owner (Optional) The object that owns the function. If the function500 * isn't global then this argument is required. This could be the namespace that501 * the function belongs to or the object on which it's502 * a method.503 * @param {Boolean} registerPrototype (Optional) Indicates that the prototype should504 * also be instrumented. Setting to true has the same effect as calling505 * registerConstructor().506 * @return {Void}507 * @method registerFunction508 * @static509 */ 510 registerFunction : function(name /*:String*/, owner /*:Object*/, registerPrototype /*:Boolean*/) /*:Void*/{511 512 //figure out the function name without namespacing513 _yuitest_coverfunc("build/profiler/profiler.js", "registerFunction", 387);514_yuitest_coverline("build/profiler/profiler.js", 390);515var funcName = (name.indexOf(".") > -1 ? 516 name.substring(name.lastIndexOf(".")+1) : name),517 method,518 prototype;519 520 //if owner isn't an object, try to find it from the name521 _yuitest_coverline("build/profiler/profiler.js", 396);522if (!L.isObject(owner)){523 _yuitest_coverline("build/profiler/profiler.js", 397);524owner = eval(name.substring(0, name.lastIndexOf(".")));525 }526 527 //get the method and prototype528 _yuitest_coverline("build/profiler/profiler.js", 401);529method = owner[funcName];530 _yuitest_coverline("build/profiler/profiler.js", 402);531prototype = method.prototype;532 533 //see if the method has already been registered534 _yuitest_coverline("build/profiler/profiler.js", 405);535if (L.isFunction(method) && !method.__yuiProfiled){536 537 //replace the function with the profiling one538 _yuitest_coverline("build/profiler/profiler.js", 408);539owner[funcName] = this.instrument(name, method);540 541 /*542 * Store original function information. We store the actual543 * function as well as the owner and the name used to identify544 * the function so it can be restored later.545 */546 _yuitest_coverline("build/profiler/profiler.js", 415);547container[name].__yuiOwner = owner;548 _yuitest_coverline("build/profiler/profiler.js", 416);549container[name].__yuiFuncName = funcName; //overwrite with less-specific name550 551 //register prototype if necessary552 _yuitest_coverline("build/profiler/profiler.js", 419);553if (registerPrototype) { 554 _yuitest_coverline("build/profiler/profiler.js", 420);555this.registerObject(name + ".prototype", prototype); 556 }557 558 }559 560 },561 562 563 /**564 * Sets up an object for profiling. It takes the object and looks for functions.565 * When a function is found, registerMethod() is called on it. If set to recrusive566 * mode, it will also setup objects found inside of this object for profiling, 567 * using the same methodology.568 * @param {String} name The name of the object to profile (shows up in report).569 * @param {Object} owner (Optional) The object represented by the name.570 * @param {Boolean} recurse (Optional) Determines if subobject methods are also profiled.571 * @return {Void}572 * @method registerObject573 * @static574 */575 registerObject : function (name /*:String*/, object /*:Object*/, recurse /*:Boolean*/) /*:Void*/{576 577 //get the object578 _yuitest_coverfunc("build/profiler/profiler.js", "registerObject", 440);579_yuitest_coverline("build/profiler/profiler.js", 443);580object = (L.isObject(object) ? object : eval(name));581 582 //save the object583 _yuitest_coverline("build/profiler/profiler.js", 446);584container[name] = object;585 586 _yuitest_coverline("build/profiler/profiler.js", 448);587for (var prop in object) {588 _yuitest_coverline("build/profiler/profiler.js", 449);589if (typeof object[prop] == "function"){590 _yuitest_coverline("build/profiler/profiler.js", 450);591if (prop != "constructor" && prop != "superclass"){ //don't do constructor or superclass, it's recursive592 _yuitest_coverline("build/profiler/profiler.js", 451);593this.registerFunction(name + "." + prop, object);594 }595 } else {_yuitest_coverline("build/profiler/profiler.js", 453);596if (typeof object[prop] == "object" && recurse){597 _yuitest_coverline("build/profiler/profiler.js", 454);598this.registerObject(name + "." + prop, object[prop], recurse);599 }}600 }601 602 }, 603 604 /**605 * Removes a constructor function from profiling. Reverses the registerConstructor() method.606 * @param {String} name The full name of the function including namespacing. This607 * is the name of the function that is stored in the report.608 * @return {Void}609 * @method unregisterFunction610 * @static611 */ 612 unregisterConstructor : function(name /*:String*/) /*:Void*/{613 614 //see if the method has been registered615 _yuitest_coverfunc("build/profiler/profiler.js", "unregisterConstructor", 468);616_yuitest_coverline("build/profiler/profiler.js", 471);617if (L.isFunction(container[name])){618 _yuitest_coverline("build/profiler/profiler.js", 472);619this.unregisterFunction(name, true);620 } 621 },622 623 /**624 * Removes function from profiling. Reverses the registerFunction() method.625 * @param {String} name The full name of the function including namespacing. This626 * is the name of the function that is stored in the report.627 * @return {Void}628 * @method unregisterFunction629 * @static630 */ 631 unregisterFunction : function(name /*:String*/, unregisterPrototype /*:Boolean*/) /*:Void*/{632 633 //see if the method has been registered634 _yuitest_coverfunc("build/profiler/profiler.js", "unregisterFunction", 484);635_yuitest_coverline("build/profiler/profiler.js", 487);636if (L.isFunction(container[name])){637 638 //check to see if you should unregister the prototype639 _yuitest_coverline("build/profiler/profiler.js", 490);640if (unregisterPrototype){641 _yuitest_coverline("build/profiler/profiler.js", 491);642this.unregisterObject(name + ".prototype", container[name].prototype);643 }644 645 //get original data646 _yuitest_coverline("build/profiler/profiler.js", 495);647var owner /*:Object*/ = container[name].__yuiOwner,648 funcName /*:String*/ = container[name].__yuiFuncName;649 650 //delete extra information651 _yuitest_coverline("build/profiler/profiler.js", 499);652delete container[name].__yuiOwner;653 _yuitest_coverline("build/profiler/profiler.js", 500);654delete container[name].__yuiFuncName;655 656 //replace instrumented function657 _yuitest_coverline("build/profiler/profiler.js", 503);658owner[funcName] = container[name];659 660 //delete supporting information661 _yuitest_coverline("build/profiler/profiler.js", 506);662delete container[name]; 663 }664 665 666 },667 668 /**669 * Unregisters an object for profiling. It takes the object and looks for functions.670 * When a function is found, unregisterMethod() is called on it. If set to recrusive671 * mode, it will also unregister objects found inside of this object, 672 * using the same methodology.673 * @param {String} name The name of the object to unregister.674 * @param {Boolean} recurse (Optional) Determines if subobject methods should also be675 * unregistered.676 * @return {Void}677 * @method unregisterObject678 * @static679 */680 unregisterObject : function (name /*:String*/, recurse /*:Boolean*/) /*:Void*/{681 682 //get the object683 _yuitest_coverfunc("build/profiler/profiler.js", "unregisterObject", 524);684_yuitest_coverline("build/profiler/profiler.js", 527);685if (L.isObject(container[name])){ 686 _yuitest_coverline("build/profiler/profiler.js", 528);687var object = container[name]; 688 689 _yuitest_coverline("build/profiler/profiler.js", 530);690for (var prop in object) {691 _yuitest_coverline("build/profiler/profiler.js", 531);692if (typeof object[prop] == "function"){693 _yuitest_coverline("build/profiler/profiler.js", 532);694this.unregisterFunction(name + "." + prop);695 } else {_yuitest_coverline("build/profiler/profiler.js", 533);696if (typeof object[prop] == "object" && recurse){697 _yuitest_coverline("build/profiler/profiler.js", 534);698this.unregisterObject(name + "." + prop, recurse);699 }}700 }701 702 _yuitest_coverline("build/profiler/profiler.js", 538);703delete container[name];704 }705 706 }707 708 709 };...
profiler-legacy.js
Source:profiler-legacy.js
1// Copyright 2019 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4import * as ProfilerModule from './profiler.js';5self.Profiler = self.Profiler || {};6Profiler = Profiler || {};7/** @constructor */8Profiler.CPUProfileFlameChart = ProfilerModule.CPUProfileFlameChart.CPUProfileFlameChart;9/** @constructor */10Profiler.CPUProfileView = ProfilerModule.CPUProfileView.CPUProfileView;11/** @constructor */12Profiler.CPUProfileHeader = ProfilerModule.CPUProfileView.CPUProfileHeader;13/** @constructor */14Profiler.HeapProfileView = ProfilerModule.HeapProfileView.HeapProfileView;15/** @constructor */16Profiler.SamplingHeapProfileType = ProfilerModule.HeapProfileView.SamplingHeapProfileType;17/** @constructor */18Profiler.SamplingHeapProfileNode = ProfilerModule.HeapProfileView.SamplingHeapProfileNode;19/** @constructor */20Profiler.HeapProfilerPanel = ProfilerModule.HeapProfilerPanel.HeapProfilerPanel;21/** @constructor */22Profiler.HeapSnapshotSortableDataGrid = ProfilerModule.HeapSnapshotDataGrids.HeapSnapshotSortableDataGrid;23/** @constructor */24Profiler.HeapSnapshotContainmentDataGrid = ProfilerModule.HeapSnapshotDataGrids.HeapSnapshotContainmentDataGrid;25/** @constructor */26Profiler.HeapSnapshotRetainmentDataGrid = ProfilerModule.HeapSnapshotDataGrids.HeapSnapshotRetainmentDataGrid;27/** @constructor */28Profiler.HeapSnapshotConstructorsDataGrid = ProfilerModule.HeapSnapshotDataGrids.HeapSnapshotConstructorsDataGrid;29/** @constructor */30Profiler.HeapSnapshotDiffDataGrid = ProfilerModule.HeapSnapshotDataGrids.HeapSnapshotDiffDataGrid;31/** @constructor */32Profiler.HeapSnapshotGridNode = ProfilerModule.HeapSnapshotGridNodes.HeapSnapshotGridNode;33/** @constructor */34Profiler.HeapSnapshotDiffNode = ProfilerModule.HeapSnapshotGridNodes.HeapSnapshotDiffNode;35/** @constructor */36Profiler.HeapSnapshotProxy = ProfilerModule.HeapSnapshotProxy.HeapSnapshotProxy;37/** @constructor */38Profiler.HeapSnapshotWorkerProxy = ProfilerModule.HeapSnapshotProxy.HeapSnapshotWorkerProxy;39/** @constructor */40Profiler.HeapSnapshotProviderProxy = ProfilerModule.HeapSnapshotProxy.HeapSnapshotProviderProxy;41/** @constructor */42Profiler.HeapSnapshotView = ProfilerModule.HeapSnapshotView.HeapSnapshotView;43/** @constructor */44Profiler.HeapSnapshotProfileType = ProfilerModule.HeapSnapshotView.HeapSnapshotProfileType;45/** @constructor */46Profiler.HeapProfileHeader = ProfilerModule.HeapSnapshotView.HeapProfileHeader;47/** @constructor */48Profiler.HeapTimelineOverview = ProfilerModule.HeapTimelineOverview.HeapTimelineOverview;49/** @constructor */50Profiler.IsolateSelector = ProfilerModule.IsolateSelector.IsolateSelector;51/** @constructor */52Profiler.LiveHeapProfileView = ProfilerModule.LiveHeapProfileView.LiveHeapProfileView;53/** @constructor */54Profiler.LiveHeapProfileView.ActionDelegate = ProfilerModule.LiveHeapProfileView.ActionDelegate;55/** @constructor */56Profiler.ProfileDataGridNode = ProfilerModule.ProfileDataGrid.ProfileDataGridNode;57/** @constructor */58Profiler.ProfileHeader = ProfilerModule.ProfileHeader.ProfileHeader;59/** @enum {symbol} */60Profiler.ProfileHeader.Events = ProfilerModule.ProfileHeader.Events;61/** @constructor */62Profiler.ProfileLauncherView = ProfilerModule.ProfileLauncherView.ProfileLauncherView;63/** @constructor */64Profiler.ProfileType = ProfilerModule.ProfileHeader.ProfileType;65/** @constructor */66Profiler.ProfileTypeRegistry = ProfilerModule.ProfileTypeRegistry.ProfileTypeRegistry;67Profiler.ProfileTypeRegistry.instance = ProfilerModule.ProfileTypeRegistry.instance;68/** @constructor */69Profiler.ProfileView = ProfilerModule.ProfileView.ProfileView;70/** @constructor */71Profiler.ProfilesPanel = ProfilerModule.ProfilesPanel.ProfilesPanel;72/** @constructor */73Profiler.ProfileTypeSidebarSection = ProfilerModule.ProfilesPanel.ProfileTypeSidebarSection;74/** @constructor */...
screeps-profiler-tests.ts
Source:screeps-profiler-tests.ts
1import profiler = require("screeps-profiler");2function testFunction() {3}4class TestClass {5 private readonly dummy: string;6}7const testObj = {8 foo() {9 },10};11profiler.enable();12profiler.wrap(testFunction);13profiler.registerClass(TestClass, "TestClass");14profiler.registerObject(testObj, "testObj");15profiler.registerFN(testFunction);16profiler.registerFN(testFunction, "testFunction");17const ticks = 100;18const filterName = "test";19Game.profiler.profile(ticks);20Game.profiler.profile(ticks, filterName);21Game.profiler.stream(ticks);22Game.profiler.stream(ticks, filterName);23Game.profiler.email(ticks);24Game.profiler.email(ticks, filterName);25Game.profiler.background();26Game.profiler.background(filterName);27Game.profiler.output();28Game.profiler.output(100);29Game.profiler.reset();...
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var test = new wpt('www.webpagetest.org', options.key);5var testOptions = {6};7test.runTest(testUrl, testOptions, function(err, data) {8 if (err) return console.error(err);9 test.getTestStatus(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 test.getTestResults(data.data.testId, function(err, data) {12 if (err) return console.error(err);13 console.log(data);14 });15 });16});17var wpt = require('webpagetest');18var options = {19};20var test = new wpt('www.webpagetest.org', options.key);21var testOptions = {22};23test.runTest(testUrl, testOptions, function(err, data) {24 if (err) return console.error(err);25 test.getTestStatus(data.data.testId, function(err, data) {26 if (err) return console.error(err);27 test.getTestResults(data.data.testId, function(err, data) {28 if (err) return console.error(err);29 console.log(data);30 });31 });32});
Using AI Code Generation
1var express = require('express');2var app = express();3app.get('/', function (req, res) {4 res.send('Hello World!');5});6app.listen(3000, function () {7 console.log('Example app listening on port 3000!');8});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org');3var url = 'www.google.com';4var options = {5};6test.runTest(url, options, function(err, data) {7 if (err) return console.error(err);8 console.log('Test status:', data.statusText);9 if (data.statusCode === 200) {10 console.log('Test completed in', data.data.average.firstView.loadTime, 'ms');11 console.log('View the test results at', data.data.summary);12 }13});14var wpt = require('webpagetest');15var test = new wpt('www.webpagetest.org');16var url = 'www.google.com';17var options = {18};19test.runTest(url, options, function(err, data) {20 if (err) return console.error(err);21 console.log('Test status:', data.statusText);22 if (data.statusCode === 200) {23 console.log('Test completed in', data.data.average.firstView.loadTime, 'ms');24 console.log('View the test results at', data.data.summary);25 }26});27var wpt = require('webpagetest');28var test = new wpt('www.webpagetest.org');29var url = 'www.google.com';30var options = {31};32test.runTest(url, options, function(err, data) {33 if (err) return console.error(err);34 console.log('Test status:', data.statusText);35 if (data.statusCode === 200) {36 console.log('Test completed in', data.data.average.firstView.loadTime, 'ms');37 console.log('View the test results at
Using AI Code Generation
1var profiler = require('wpt-profiler');2profiler.startProfiler();3profiler.stopProfiler(function(err, result){4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Result: ' + result);8 }9});10Copyright (c) 2014 Rajesh Nair
Using AI Code Generation
1var profiler = require('profiler');2var profiler = new profiler();3profiler.start();4profiler.stop();5var result = profiler.result();6console.log(result);
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.3b3a7e2d2c0f7b1e0b4a7b4d4b4a7c4a');3wpt.runTest(url, { runs: 1, location: 'Dulles:Chrome', connectivity: 'Cable' }, function(err, data) {4 if (err) return console.error(err);5 console.log('Test status: %j', data.statusText);6 wpt.getTestStatus(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log('Test status: %j', data.statusText);9 wpt.getTestResults(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log('Test results: %j', data);12 });13 });14});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!