Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
"// noprotect"
function Opa(stuff) {
  this.stuff = stuff;
}
Opa.prototype = {
  constructor: Opa,
  sayStuff: function() {
    console.log(this.stuff);
  }
};
const OpaProto = {
  sayStuff: function() {
    console.log(this.stuff);
  }  
};
//no protect
let array1 = [], array2 = [], time;
const testNumber = 1000000;
time = Date.now();
for (let i = 0; i < testNumber; i++) {
  array1.push(new Opa(Math.random()));
}
console.log('with new:', Date.now() - time);
time = Date.now();
for (let i = 0; i < testNumber; i++) {
  let o = Object.create(OpaProto);
  o.stuff = Math.random();
  array2.push(o);
}
console.log('with Object.create', Date.now() - time);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers