diff options
author | Ariel Flesler <aflesler@gmail.com> | 2009-07-24 00:57:27 +0000 |
---|---|---|
committer | Ariel Flesler <aflesler@gmail.com> | 2009-07-24 00:57:27 +0000 |
commit | 6a85898d131f9921f2d8e885a892fbdcf4d9c5c6 (patch) | |
tree | 97f5855393c3c2f914878bc28af2b7801508b6dc /speed | |
parent | 26eda09892459709d224f910038b8f6836bfd012 (diff) | |
download | jquery-6a85898d131f9921f2d8e885a892fbdcf4d9c5c6.tar.gz jquery-6a85898d131f9921f2d8e885a892fbdcf4d9c5c6.zip |
speed: committing a failing experiment of concat vs slice
Diffstat (limited to 'speed')
-rw-r--r-- | speed/slice.vs.concat.html | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/speed/slice.vs.concat.html b/speed/slice.vs.concat.html new file mode 100644 index 000000000..c061e079f --- /dev/null +++ b/speed/slice.vs.concat.html @@ -0,0 +1,46 @@ +<script type="text/javascript"> +(function(){ + // Conclusion: slice is a little faster except on Chrome + // clone() is slower on FF & IE but takes 50% on Safari & Chrome + + var SIZE = 1e4, + LOOPS = 500; + + var arr = new Array(SIZE); + for ( var i=arr.length-1; i >= 0; --i ) + arr[i] = 0; + + var t = new Date; + for ( i=0; i < LOOPS; i++ ) + arr.slice(0); + var tslice = new Date - t; + + t = new Date; + for ( i=0; i < LOOPS; i++ ) + arr.concat(); + var tconcat = new Date - t; + + // clone() is just to see how fast built-ins are + t = new Date; + for ( i=0; i < LOOPS; i++ ) + clone(arr); + var tclone = new Date - t; + + alert([ + 'slice:'+tslice, + 'concat:'+tconcat, + 'clone:'+tclone + ].join('\n')); + + + function clone(arr){ + var i = arr.length, + copy = new Array(i); + + while (i--) + copy[i] = arr[i]; + + return copy; + } +})(); +</script>
\ No newline at end of file |