Cloning Methods

Benchmark created by Adam Sanderson on


Description

Testing various ways to clone an array of data.

Preparation HTML

<script>
  var data = [];
  for (var i = 0; i < 100; i++) {
   data[i] = {
    a: i + 2,
    b: i + 3
   };
  }
  
  var copies = [];
  for (var i = 0; i < 100; i++) {
   copies[i] = {
    a: data[i].a,
    b: data[i].b
   }
  };
  
  var proxies = [];
  
  function createProxy(src) {
   function Proxy() {};
   Proxy.prototype = src;
   return new Proxy();
  }
  
  for (var i = 0; i < 100; i++) {
   proxies[i] = createProxy(data[i]);
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Accessing Objects
var count = 0
for (var i = 0, len = copies.length; i < len; i++) {
 count = count + copies[i].a + copies[i].b
}
ready
Accessing Proxies
var count = 0
for (var i = 0, len = proxies.length; i < len; i++) {
 count = count + proxies[i].a + proxies[i].b
}
ready

Revisions

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

  • Revision 1: published by Adam Sanderson on