码迷,mamicode.com
首页 > Web开发 > 详细

js两种写法执行速度比较

时间:2018-02-24 19:30:33      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:test   turn   return   log   this   pos   function   比较   写法   

记录

function test1(){
  this.say = function(){}

}

function test2(){
this.say = function(){}
return this;
}

 

 

console.time();
var t = new test1();
for (var i=0;i<100000;i++) {
t.say();
}
console.timeEnd()

 


console.time();
for (var i=0;i<100000;i++) {
test2().say();
}
console.timeEnd()

 

测试下来第一种方法比第二种调用的方法快了差不多6倍

 

js两种写法执行速度比较

标签:test   turn   return   log   this   pos   function   比较   写法   

原文地址:https://www.cnblogs.com/MainActivity/p/8467284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!