Skip to content

Instantly share code, notes, and snippets.

@MKelm
Created Aug 2, 2013
Embed
What would you like to do?
Prototyping speed test (prototyping 19,6x faster in node-webkit)
<!DOCTYPE HTML>
<html>
<head>
<title>Test Prototyping</title>
<script language="javascript">
var X,Y, x,y, i, intNow;
X = function() {};
X.prototype.message = function(s) { var mymessage = s + "";}
X.prototype.addition = function(i,j) { return (i *2 + j * 2) / 2; }
Y = function() {
this.message = function(s) { var mymessage = s + "";}
this.addition = function(i,j) { return (i *2 + j * 2) / 2; }
};
intNow = (new Date()).getTime();
for (i = 0; i < 1000000; i++) {
y = new Y();
y.message('hi');
y.addition(i,2)
}
console.log((new Date()).getTime() - intNow); // without prototyping
intNow = (new Date()).getTime();
for (i = 0; i < 1000000; i++) {
x = new X();
x.message('hi');
x.addition(i,2)
}
console.log((new Date()).getTime() - intNow); // with prototyping
</script>
</head>
<body>
</body>
</html>
@MKelm
Copy link
Author

MKelm commented Aug 2, 2013

Milliseconds on my node-webkit 0.6.2 / Linux Debian 64bit:

  • without prototyping 755 ms
  • with prototyping 42 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment