Skip to content

Instantly share code, notes, and snippets.

@rinunu
Created June 21, 2010 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rinunu/446391 to your computer and use it in GitHub Desktop.
Save rinunu/446391 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
var tests = {};
tests.push = function(){
var array = [];
for(var i = 0; i < 10000; i++){
array.push("test");
}
}
tests.length = function(){
var array = [];
for(var i = 0; i < 10000; i++){
array[array.length] = "test";
}
}
tests.unshift = function(){
var array = [];
for(var i = 0; i < 10000; i++){
array.unshift("test");
}
}
tests.splice = function(){
var array = [];
for(var i = 0; i < 10000; i++){
array.splice(array, 0, 0, "test");
}
}
tests.set = function(){
var array = [];
for(var i = 0; i < 10000; i++){
array[i] = "test";
}
}
function run(){
for(var i in tests){
var start = new Date();
tests[i]();
$("<tr><td>" + i + "</td><td>" + (new Date - start) + "ms</td></tr>").appendTo($("#result"));
}
}
$(run);
</script>
</head>
<body>
result
<table id="result">
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment