array join vs string connect

JavaScript performance comparison

Revision 11 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var alphabet = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
  var alphatmp = [];

  for (i = 0; i < 20; i++)
  alphatmp.push(alphabet);

  var str_to_split = alphatmp.join(',');
  var myarray = str_to_split.split(',');
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
array join
var tmp = [];
for (i = 0; i < myarray.length; i++) {
  tmp.push(myarray[i]);
}

var output = tmp.join('');
pending…
string connect
var output = '';
for (i = 0; i < myarray.length; i++) {
  output += myarray[i];
}
pending…
My test
$('input[type=text],input[type=password],input[type=radio],input[type=checkbox],input[type=file]').each(function() {

  $(this).addClass('type_' + this.type);
});

$('select').each(function() {

  $(this).addClass('type_select');
});


$("input[readOnly='readOnly']").each(function() {

  $(this).addClass('readonly');
});

$("button[type='button']").each(function() {

  $(this).addClass('button_button');
});

$("button[type='submit']").each(function() {

  $(this).addClass('button_submit');
});

$("input[type='submit']").each(function() {

  $(this).addClass('input_submit');
});

$("input[type='button']").each(function() {

  $(this).addClass('input_button');
});

$("select[disabled='disabled']").each(function() {

  $(this).addClass('disabled');
});
pending…
My Test1
var formElements = $('input, button, select');

formElements.find('input[type=text],input[type=password],input[type=radio],input[type=checkbox],input[type=file]').each(function() {

  $(this).addClass('type_' + this.type);
});

formElements.find('select').each(function() {

  $(this).addClass('type_select');
});


formElements.find("input[readOnly='readOnly']").each(function() {

  $(this).addClass('readonly');
});

formElements.find("button[type='button']").each(function() {

  $(this).addClass('button_button');
});

formElements.find("button[type='submit']").each(function() {

  $(this).addClass('button_submit');
});

formElements.find("input[type='submit']").each(function() {

  $(this).addClass('input_submit');
});

formElements.find("input[type='button']").each(function() {

  $(this).addClass('input_button');
});

formElements.find("select[disabled='disabled']").each(function() {

  $(this).addClass('disabled');
});
pending…
My Test2
$('input[type=text],input[type=password],input[type=radio],input[type=checkbox],input[type=file]').each(function() {

  $(this).addClass('type_' + this.type);
});

$('select').addClass('type_select');

$("input[readOnly='readOnly']").addClass('readonly');

$("button[type='button']").addClass('button_button');

$("button[type='submit']").addClass('button_submit');

$("input[type='submit']").addClass('input_submit');

$("input[type='button']").addClass('input_button');

$("select[disabled='disabled']").addClass('disabled');
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. Here’s a list of current revisions for this page:

0 comments

Add a comment