Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial perf tests for object creation

  • Loading branch information...
commit ca411eb796477d7fb129d151acce6d014da46c16 1 parent 41cb98f
Wei Kin Huang authored
Showing with 93 additions and 1 deletion.
  1. +1 −1  config.js
  2. +92 −0 perf/create.js
2  config.js
View
@@ -9,7 +9,7 @@ module.exports = {
},
src : [ "core.js", "create.js", "mutator.static.js", "mutator.nowrap.js", "mutator.alias.js", "mutator.bind.js", "observer.js", "mutator.observable.js", "namespace.js", "export.js" ],
unit : [ "core.js", "create.js", "mutator.static.js", "mutator.nowrap.js", "mutator.alias.js", "mutator.bind.js", "observer.js", "mutator.observable.js", "namespace.js", "export.js" ],
- perf : [],
+ perf : [ "create.js" ],
docs : [ "classify.docs.js" ],
env : {
node : true,
92 perf/create.js
View
@@ -0,0 +1,92 @@
+Benchmark.test("core", function(test) {
+ test("define basic class", function() {
+ var ci = create({
+ init : function(a) {
+ this.a = a;
+ },
+ a : function() {
+ return 1;
+ }
+ });
+ });
+
+ var ci = create({
+ init : function(a) {
+ this.a = a;
+ },
+ a : function() {
+ return 1;
+ }
+ });
+ test("define inherited class", function() {
+ var cp = create(ci, {
+ init : function(a) {
+ this.a = a;
+ },
+ a : function() {
+ return 1;
+ }
+ });
+ });
+
+ var cl = create({
+ a : function() {
+ return 1;
+ }
+ });
+
+ test("init with no init function", function() {
+ var a = new cl();
+ });
+
+ var ci = create({
+ init : function(a) {
+ this.a = a;
+ },
+ a : function() {
+ return 1;
+ }
+ });
+
+ test("init with init function", function() {
+ var a = new ci();
+ });
+
+ var Person = create({
+ init : function(name) {
+ this.name = name;
+ },
+ setAddress : function(country, city, street) {
+ this.country = country;
+ this.city = city;
+ this.street = street;
+ }
+ });
+
+ var p = new Person("Mary");
+ test("access method 0 chain", function() {
+ p.setAddress("France", "Paris", "CH");
+ });
+
+ var FrenchGuy = create(Person, {
+ setAddress : function(city, street) {
+ this.parent("France", city, street);
+ }
+ });
+
+ var p2 = new FrenchGuy("Mary");
+ test("access parent 1 chain", function() {
+ p2.setAddress("Paris", "CH");
+ });
+
+ var ParisLover = create(FrenchGuy, {
+ setAddress : function(street) {
+ this.parent("Paris", street);
+ }
+ });
+
+ var p3 = new ParisLover("Mary");
+ test("access parent 2 chain", function() {
+ p3.setAddress("CH");
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.