Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. arr = new Array();
  2. // vs.
  3. arr = [];
  4.  
  5. arr = new Array(10000);
  6. // vs.
  7. arr = [];
  8. arr.length = 10000;
  9.  
  10. 'use strict';
  11.  
  12. (function() {
  13.  
  14. // variables
  15. var suite, arr;
  16.  
  17. // new benchmark object
  18. suite = new Benchmark.Suite();
  19.  
  20. // add tests
  21. suite.add('var arr = new array();', function() {
  22. arr = new Array();
  23. })
  24. .add('var arr = [];', function() {
  25. arr = [];
  26. })
  27. // invoke before running
  28. .on('start', function() {
  29. console.log('Running tests, please wait...');
  30. })
  31. // add listeners
  32. .on('cycle', function(event) {
  33. console.log(String(event.target));
  34. })
  35. .on('complete', function() {
  36. console.log('Fastest is ' + this.filter('fastest').map('name'));
  37. })
  38. // put in queue and run
  39. .run({ 'async': true, 'queued': true });
  40.  
  41. // new benchmark object
  42. suite = new Benchmark.Suite();
  43.  
  44. // add tests
  45. suite.add('var arr = new array(10000);', function() {
  46. arr = new Array(10000);
  47. })
  48. .add('var arr = []; arr.length = 10000;', function() {
  49. arr = [];
  50. arr.length = 10000;
  51. })
  52. // invoke before running
  53. .on('start', function() {
  54. console.log('Running tests, please wait...');
  55. })
  56. // add listeners
  57. .on('cycle', function(event) {
  58. console.log(String(event.target));
  59. })
  60. .on('complete', function() {
  61. console.log('Fastest is ' + this.filter('fastest').map('name'));
  62. })
  63. // put in queue and run
  64. .run({ 'async': true, 'queued': true });
  65.  
  66. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement