Guest User

Untitled

a guest
Feb 4th, 2016
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var Obj = function(){
  3.  
  4. }
  5.  
  6. Obj.prototype.test = function(){
  7. console.log("ok");
  8. }
  9. Obj.prototype.test1 = function(){
  10. console.log("ok");
  11. }
  12. Obj.prototype.test2 = function(){
  13. console.log("ok");
  14. }
  15.  
  16. var Obj2 = function(){
  17.  
  18. function test(){
  19. console.log("ok");
  20. }
  21. function test1(){
  22. console.log("ok");
  23. }
  24. function test2(){
  25. console.log("ok");
  26. }
  27. Obj2.prototype.test = test;
  28. Obj2.prototype.test1 = test1;
  29. Obj2.prototype.test2 = test2;
  30. }
  31.  
  32. function main(){
  33.  
  34. var d = new Date();
  35. var startTime = d.getTime();
  36. var i,nb = 1000000;
  37.  
  38. var t = [];
  39. for(i=0;i<nb;i++) t[i] = new Obj();
  40.  
  41.  
  42. d = new Date();
  43. console.log('test 1 --> '+(d.getTime() - startTime) );
  44.  
  45. startTime = d.getTime();
  46.  
  47. var t = [];
  48. for(i=0;i<nb;i++) t[i] = new Obj2();
  49.  
  50. d = new Date();
  51. console.log('test 2 --> '+(d.getTime() - startTime) );
  52.  
  53. }
RAW Paste Data