Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arr = new Array();
- // vs.
- arr = [];
- arr = new Array(10000);
- // vs.
- arr = [];
- arr.length = 10000;
- 'use strict';
- (function() {
- // variables
- var suite, arr;
- // new benchmark object
- suite = new Benchmark.Suite();
- // add tests
- suite.add('var arr = new array();', function() {
- arr = new Array();
- })
- .add('var arr = [];', function() {
- arr = [];
- })
- // invoke before running
- .on('start', function() {
- console.log('Running tests, please wait...');
- })
- // add listeners
- .on('cycle', function(event) {
- console.log(String(event.target));
- })
- .on('complete', function() {
- console.log('Fastest is ' + this.filter('fastest').map('name'));
- })
- // put in queue and run
- .run({ 'async': true, 'queued': true });
- // new benchmark object
- suite = new Benchmark.Suite();
- // add tests
- suite.add('var arr = new array(10000);', function() {
- arr = new Array(10000);
- })
- .add('var arr = []; arr.length = 10000;', function() {
- arr = [];
- arr.length = 10000;
- })
- // invoke before running
- .on('start', function() {
- console.log('Running tests, please wait...');
- })
- // add listeners
- .on('cycle', function(event) {
- console.log(String(event.target));
- })
- .on('complete', function() {
- console.log('Fastest is ' + this.filter('fastest').map('name'));
- })
- // put in queue and run
- .run({ 'async': true, 'queued': true });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement