1
0
Fork 0

Began adding performance tests

closure/master
Mike Gerwitz 2011-03-10 22:43:36 -05:00
parent e0fb37daa0
commit 37bf2fa353
6 changed files with 261 additions and 0 deletions

8
test/perf/README 100644
View File

@ -0,0 +1,8 @@
This directory contains the performance tests. These tests contain basic
routines that perform a single action and output the result in seconds, with a
basic description of what has been done. The timing is done via the native Date
object to ensure that it can be run both server and client-side.
It is important that each test performs only a single operation to ensure that
the prior operations have no consequences on the previous, at least when run
server-side by invoking a separate executable for each.

View File

@ -0,0 +1,91 @@
/**
* Common performance testing functionality
*
* Copyright (C) 2010 Mike Gerwitz
*
* This file is part of ease.js.
*
* ease.js is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Mike Gerwitz
* @package performance
*/
/**
* Stores start time
* @type {number}
*/
var start = 0;
/**
* Includes a module from the lib directory
*
* @param {string} name module name
*
* @return {Object} module exports
*/
exports.require = function( name )
{
return require( '../../lib/' + name );
};
/**
* A simple wrapper to perform testing and output the result
*
* @param {function()} test performance test to perform
* @param {string=} desc test description
*
* @return {undefined}
*/
exports.test = function( test, desc )
{
exports.start();
test();
exports.report( desc );
};
/**
* Starts the timer
*
* @return {undefined}
*/
exports.start = function()
{
start = ( new Date() ).getTime();
};
/**
* Outputs the time elapsed, followed by the description (if available)
*
* @param {string=} desc test description
*
* @return {undefined}
*/
exports.report = function( desc )
{
desc = desc || '';
var end = ( new Date() ).getTime(),
total = ( ( end - start ) / 1000 ).toFixed( 3 )
;
console.log( total + 's' +
( ( desc ) ? ( ': ' + desc ) : '' )
);
};

View File

@ -0,0 +1,42 @@
/**
* Tests amount of time taken to declare 1000 classes
*
* Copyright (C) 2010 Mike Gerwitz
*
* This file is part of ease.js.
*
* ease.js is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Mike Gerwitz
* @package performance
*/
var common = require( __dirname + '/common.js' ),
Class = common.require( 'class' )
count = 1000
;
common.test( function()
{
var i = count;
while ( i-- )
{
Class( {} );
}
}, 'Declare ' + count + ' empty anonymous classes' );

View File

@ -0,0 +1,43 @@
/**
* Tests amount of time taken to instantiate anonymous classes
*
* Copyright (C) 2010 Mike Gerwitz
*
* This file is part of ease.js.
*
* ease.js is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Mike Gerwitz
* @package performance
*/
var common = require( __dirname + '/common.js' ),
Class = common.require( 'class' )
count = 5000,
Foo = Class( {} )
;
common.test( function()
{
var i = count;
while ( i-- )
{
Foo();
}
}, 'Instantiate ' + count + ' empty anonymous classes' );

View File

@ -0,0 +1,44 @@
/**
* Tests amount of time taken to instantiate named classes
*
* Copyright (C) 2010 Mike Gerwitz
*
* This file is part of ease.js.
*
* ease.js is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Mike Gerwitz
* @package performance
*/
var common = require( __dirname + '/common.js' ),
Class = common.require( 'class' )
count = 5000,
Foo = Class( 'Foo', {} )
;
common.test( function()
{
var i = count;
while ( i-- )
{
// to be extra confident that V8 or another compiler won't realize this
// is useless and optimize it out
Foo();
}
}, 'Instantiate ' + count + ' empty named classes' );

View File

@ -0,0 +1,33 @@
/**
* Tests amount of time spent on requiring class module
*
* Copyright (C) 2010 Mike Gerwitz
*
* This file is part of ease.js.
*
* ease.js is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Mike Gerwitz
* @package performance
*/
var common = require( __dirname + '/common.js' );
// we run this test once because require() will cache the object in memory
common.test( function()
{
common.require( 'class' );
}, 'Require class module' );