This article mainly introduces the StopWatch function implemented byJavascript, and analyzes the related operating skills of javascript custom StopWatch to implement the test running time function based on specific examples. Friends in need can refer to the following
The example in this article describes the StopWatch function implemented by Javascript. Share it with everyone for your reference, the details are as follows:
Sometimes js is needed to write somefunctionsfor testing. If you need to test the execution time, you may need a stopwatch:
StopWatch class:
function stopWatch() { } stopWatch.prototype.Start = function () { this.startD = new Date(); return this; }; stopWatch.prototype.Stop = function () { this.startD = new Date(); return this; }; stopWatch.prototype.Seconds = function () { return Math.abs((new Date() - this.startD) / 1000); };
Usage example (test Fibonacci sequence):
The running effect is as follows :
##
The above is the detailed content of Sample code sharing of how Javascript implements the StopWatch function. For more information, please follow other related articles on the PHP Chinese website!