function declarations test 2 glj

JavaScript performance comparison

Revision 2 of this test case created by Micah

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Collin (declaration)
var test = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11,12,13,14,15],
    [16,17,18,19,20],
    [21,22,23, 24,25]
];

function snail(array) {
  
  const sortedArray = [];
  
  const getArrayLength = (array) => {
    if(array) {
      return array.length
    } else {
      return 0;
    }
  }
  
  while(array.length) {

    for(let i = 0; i < getArrayLength(array[0]); i++) {
      sortedArray.push(array[0][i]);
    }
    array.splice(0, 1);
    
    for(let i = 0; i < getArrayLength(array); i++) {
      sortedArray.push(array[i][array.length]);
      array[i].splice(array.length, 1);
    }
    
    for(let i = getArrayLength(array[0]) - 1; i >= 0; i--) {
      sortedArray.push(array[array[0].length - 1][i]);
    }
    array.splice(array.length - 1, 1);
    
    for(let i = getArrayLength(array); i > 0; i--) {
      sortedArray.push(array[i - 1][0]);
      array[i - 1].splice(0, 1);
    }
  
  }
    
    return sortedArray;
    
  }
snail(test);
pending…
Collin (expression)
var test = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11,12,13,14,15],
    [16,17,18,19,20],
    [21,22,23, 24,25]
];

var snail = function(array) {
  
  const sortedArray = [];
  
  const getArrayLength = (array) => {
    if(array) {
      return array.length
    } else {
      return 0;
    }
  }
  
  while(array.length) {

    for(let i = 0; i < getArrayLength(array[0]); i++) {
      sortedArray.push(array[0][i]);
    }
    array.splice(0, 1);
    
    for(let i = 0; i < getArrayLength(array); i++) {
      sortedArray.push(array[i][array.length]);
      array[i].splice(array.length, 1);
    }
    
    for(let i = getArrayLength(array[0]) - 1; i >= 0; i--) {
      sortedArray.push(array[array[0].length - 1][i]);
    }
    array.splice(array.length - 1, 1);
    
    for(let i = getArrayLength(array); i > 0; i--) {
      sortedArray.push(array[i - 1][0]);
      array[i - 1].splice(0, 1);
    }
  
  }
    
    return sortedArray;
    
  }
snail(test);
pending…
test 3 (declaration)
var test = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11,12,13,14,15],
    [16,17,18,19,20],
    [21,22,23, 24,25]
];

function snail(array) {
   let res = [];
   arr = [];
   for(let i = 0; i < 25; i++ ){
        
        res.push('1');

    }
    return res;
}

snail(test);
pending…
test 2 (expression)
var test = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11,12,13,14,15],
    [16,17,18,19,20],
    [21,22,23, 24,25]
];

var snail = function(array) {
   let res = [];
   arr = [];
   for(let i = 0; i < 25; i++ ){
        
        res.push('1');

    }
    return res;
}

snail(test);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments