有时会需要js来写一些函数进行测试,如果需要测试执行时间,可能需要一个stopwatch:
StopWatch类:
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); };
用法(测试斐波那契数列):
var sw = new stopWatch().Start(); (function f(n){return n == 1 || n == 2 ? 1 : f(n-1)+f(n-2);})(45); alert(sw.Seconds());
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索测试
, 斐波那契数列
, new
, return
, function
, this
, prototype
斐波那契
javascript实现计算器、javascript实现进度条、javascript底层实现、javascript实现继承、javascript实现ajax,以便于您获取更多的相关知识。
时间: 2024-09-13 02:25:09