1
0
Fork 0

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.
perfodd
Mike Gerwitz 2014-03-07 01:55:46 -05:00
parent 55e993a74d
commit 433dd4fb7a
3 changed files with 285 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* 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' );

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* 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' );

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* 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' );