From 433dd4fb7a15f60c5f711170fb45610573f3d55e Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Fri, 7 Mar 2014 01:55:46 -0500 Subject: [PATCH] Trait definition and mixin performance test cases Does not yet include many more detailed tests, such as method invocation times, which will be of particular interest. While definitions are indeed interesting, they often occur when a program is loading---when the user is expecting to wait. Not so for method invocations. --- test/perf/perf-trait-define.js | 40 ++++++++++ test/perf/perf-trait-methods.js | 126 ++++++++++++++++++++++++++++++++ test/perf/perf-trait-mixin.js | 119 ++++++++++++++++++++++++++++++ 3 files changed, 285 insertions(+) create mode 100644 test/perf/perf-trait-define.js create mode 100644 test/perf/perf-trait-methods.js create mode 100644 test/perf/perf-trait-mixin.js diff --git a/test/perf/perf-trait-define.js b/test/perf/perf-trait-define.js new file mode 100644 index 0000000..f4d6af7 --- /dev/null +++ b/test/perf/perf-trait-define.js @@ -0,0 +1,40 @@ +/** + * Tests amount of time taken to declare N anonymous traits + * + * Copyright (C) 2010, 2011, 2013 Mike Gerwitz + * + * This file is part of GNU ease.js. + * + * ease.js is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Contrast with respective class test. + */ + +var common = require( __dirname + '/common.js' ), + Trait = common.require( 'Trait' ), + + count = 1000 +; + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + Trait( {} ); + } + +}, count, 'Declare ' + count + ' empty anonymous traits' ); diff --git a/test/perf/perf-trait-methods.js b/test/perf/perf-trait-methods.js new file mode 100644 index 0000000..4a03efd --- /dev/null +++ b/test/perf/perf-trait-methods.js @@ -0,0 +1,126 @@ +/** + * Tests amount of time taken defining and invoking methods passing through + * traits + * + * Copyright (C) 2010, 2011, 2013 Mike Gerwitz + * + * This file is part of GNU ease.js. + * + * ease.js is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Contrast with respective class test. + */ + +var common = require( __dirname + '/common.js' ), + Trait = common.require( 'Trait' ), + Class = common.require( 'class' ), + Interface = common.require( 'interface' ), + + count = 1000 +; + + +var I = Interface( +{ + a: [], + b: [], + c: [], +} ); + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + Trait( + { + a: function() {}, + b: function() {}, + c: function() {}, + } ); + } + +}, count, +'Declare ' + count + ' empty anonymous traits with few concrete methods' ); + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + Trait( + { + 'virtual a': function() {}, + 'virtual b': function() {}, + 'virtual c': function() {}, + } ); + } + +}, count, +'Declare ' + count + ' empty anonymous traits with few virtual methods' ); + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + Trait( + { + 'abstract a': [], + 'abstract b': [], + 'abstract c': [], + } ); + } + +}, count, +'Declare ' + count + ' empty anonymous traits with few abstract methods' ); + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + Trait.implement( I ).extend( {} ); + } + +}, count, +'Declare ' + count + ' empty anonymous traits implementing interface ' + + 'with few methods' ); + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + Trait.implement( I ).extend( + { + 'abstract override a': function() {}, + 'abstract override b': function() {}, + 'abstract override c': function() {}, + } ); + } + +}, count, +'Declare ' + count + ' empty anonymous traits with few ' + + 'abstract overrides, implementing interface' ); diff --git a/test/perf/perf-trait-mixin.js b/test/perf/perf-trait-mixin.js new file mode 100644 index 0000000..23d0200 --- /dev/null +++ b/test/perf/perf-trait-mixin.js @@ -0,0 +1,119 @@ +/** + * Tests amount of time taken to declare N classes mixing in traits of + * various sorts + * + * Copyright (C) 2010, 2011, 2013 Mike Gerwitz + * + * This file is part of GNU ease.js. + * + * ease.js is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Contrast with respective class test. + */ + +var common = require( __dirname + '/common.js' ), + Trait = common.require( 'Trait' ), + Class = common.require( 'class' ), + Interface = common.require( 'interface' ), + + count = 1000 +; + +// we don't care about declare time; we're testing mixin time +var Te = Trait( {} ); + +var Tv = Trait( +{ + 'virtual a': function() {}, + 'virtual b': function() {}, + 'virtual c': function() {}, +} ); + +var I = Interface( +{ + a: [], + b: [], + c: [], +} ); +var Cv = Class.implement( I ).extend( +{ + 'virtual a': function() {}, + 'virtual b': function() {}, + 'virtual c': function() {}, +} ); + +var To = Trait.implement( I ).extend( +{ + 'virtual abstract override a': function() {}, + 'virtual abstract override b': function() {}, + 'virtual abstract override c': function() {}, +} ); + + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + // extend to force lazy mixin + Class.use( Te ).extend( {} ); + } + +}, count, 'Mix in ' + count + ' empty traits' ); + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + // extend to force lazy mixin + Class.use( Tv ).extend( {} ); + } + +}, count, 'Mix in ' + count + ' traits with few virtual methods' ); + + +// now override 'em +common.test( function() +{ + var i = count; + + while ( i-- ) + { + Class.use( Tv ).extend( + { + 'override virtual a': function() {}, + 'override virtual b': function() {}, + 'override virtual c': function() {}, + } ); + } + +}, count, 'Mix in and override ' + count + + ' traits with few virtual methods' ); + + +common.test( function() +{ + var i = count; + + while ( i-- ) + { + Cv.use( To ).extend( {} ); + } + +}, count, 'Mix in trait that overrides class methods' );