Permalink
Browse files

Caching results of calls to callsSuper(func). JS.Class load time cut …

…by 50%, test suite cut by 66%, class creation benchmark cut by 80%.
  • Loading branch information...
1 parent 195ff36 commit 59cae2a8f2b23ff9839f7a908e71afd9268b896b @jcoglan jcoglan committed Aug 1, 2008
Showing with 23 additions and 1 deletion.
  1. +3 −1 source/class.js
  2. +20 −0 test/benchmarks.html
View
@@ -64,7 +64,9 @@ JS = {
},
callsSuper: function(func) {
- return /\bcallSuper\b/.test(func.toString());
+ return func.SUPER === undefined
+ ? func.SUPER = /\bcallSuper\b/.test(func.toString())
+ : func.SUPER;
},
mask: function(func) {
View
@@ -123,6 +123,26 @@
benchmark(function() {
s.contains( new TodoItem ( Math.round(Math.random() * 10000) ) );
}, 5000);
+ }},
+
+ testClassCreation: function() { with(this) {
+ benchmark(function() {
+ var K = function() {};
+ K.prototype.method1 = function() {};
+ K.prototype.method2 = function() {};
+ }, 100);
+ benchmark(function() {
+ var K = Class.create({
+ method1: function(){},
+ method2: function(){}
+ });
+ }, 100);
+ benchmark(function() {
+ var K = new JS.Class({
+ method1: function(){},
+ method2: function(){}
+ });
+ }, 100);
}}
});

0 comments on commit 59cae2a

Please sign in to comment.