交换数组项性能比较

JavaScript performance comparison

Test case created by jjeejj

Preparation code

<script>
  let arr = [1,2,3,4,5,6,7,8,9,23,45,676,2323,678,'32','dfdf'];
</script>

    

Preparation code output

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
splice方法
function exchange(arr,index1, index2){
   arr[index1] = arr.splice(index2,1,arr[index1]);
   return arr;
};
exchange(arr, 3,7);
pending…
temp 变量
function exchange(arr,index1, index2){
   let temp = arr[index1];
   arr[index1] = arr[index2];
   arr[index2] = temp;
   return arr;
};
exchange(arr, 3,7);
pending…
es6解构赋值
function exchange(arr,index1, index2){
  [arr[index1],arr[index2]] = [arr[index2],arr[index1]]
   return arr;
};
exchange(arr, 3,7);
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