From 37bf2fa353e8922d7a663c8f9c061d3192be949a Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 10 Mar 2011 22:43:36 -0500 Subject: [PATCH] Began adding performance tests --- test/perf/README | 8 +++ test/perf/common.js | 91 ++++++++++++++++++++++++ test/perf/perf-class-define.js | 42 +++++++++++ test/perf/perf-class-inst-anon-empty.js | 43 +++++++++++ test/perf/perf-class-inst-named-empty.js | 44 ++++++++++++ test/perf/perf-class-require.js | 33 +++++++++ 6 files changed, 261 insertions(+) create mode 100644 test/perf/README create mode 100644 test/perf/common.js create mode 100644 test/perf/perf-class-define.js create mode 100644 test/perf/perf-class-inst-anon-empty.js create mode 100644 test/perf/perf-class-inst-named-empty.js create mode 100644 test/perf/perf-class-require.js diff --git a/test/perf/README b/test/perf/README new file mode 100644 index 0000000..9c95d99 --- /dev/null +++ b/test/perf/README @@ -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. diff --git a/test/perf/common.js b/test/perf/common.js new file mode 100644 index 0000000..75ec0cf --- /dev/null +++ b/test/perf/common.js @@ -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 . + * + * @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 ) : '' ) + ); +}; + diff --git a/test/perf/perf-class-define.js b/test/perf/perf-class-define.js new file mode 100644 index 0000000..b4eb20b --- /dev/null +++ b/test/perf/perf-class-define.js @@ -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 . + * + * @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' ); diff --git a/test/perf/perf-class-inst-anon-empty.js b/test/perf/perf-class-inst-anon-empty.js new file mode 100644 index 0000000..69220a8 --- /dev/null +++ b/test/perf/perf-class-inst-anon-empty.js @@ -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 . + * + * @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' ); diff --git a/test/perf/perf-class-inst-named-empty.js b/test/perf/perf-class-inst-named-empty.js new file mode 100644 index 0000000..5ee920f --- /dev/null +++ b/test/perf/perf-class-inst-named-empty.js @@ -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 . + * + * @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' ); diff --git a/test/perf/perf-class-require.js b/test/perf/perf-class-require.js new file mode 100644 index 0000000..065c50d --- /dev/null +++ b/test/perf/perf-class-require.js @@ -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 . + * + * @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' ); +