Skip to content

Instantly share code, notes, and snippets.

@MKelm
Created August 2, 2013 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MKelm/6143399 to your computer and use it in GitHub Desktop.
Save MKelm/6143399 to your computer and use it in GitHub Desktop.
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