executionerjs v1.0.5
executionerjs
Simple web application for running JavaScript performance tests
Compability
executionerjs uses performance.now
which is supported in all major browsers with
exceptions. Please see User Timing API @ caniuse.com for an
updated list.
Installing with npm
Navigate to the project where you want to run executionerjs and run command:
npm install executionerjs --save-dev
Cloning from git and installing
Navigate to the location where you want to download executionerjs with your favorite terminal application and run command:
git clone https://github.com/linusjaderlund/executionerjs.git
Then navigate to project root folder and run command:
npm install
NOTE: After npm installation grunt will run automatically through npm
pre publish script. Grunt compiles all script files and bundles them.
If you want to do this later on again you can run one of the following commands:
grunt dev
(only bundles scripts with browserify for development use),
grunt production
(which also include babel and minifies bundle) or you can run
grunt
(which does the same as "dev" but also starts watch and rebuilds on changes).
Include executionerjs in your project
By require
If you did not use npm then you can require executionerjs like this:
const executioner = require('./relative/path/to/executionerjs/folder');
If you used npm to install executionerjs, require like following:
const executioner = require('executionerjs');
By script tag
<script type="text/javascript" src="path/to/executioner.min.js"></script>
<script type="text/javascript" src="path/to/your/scripts..."></script>
Types of test
Executions over time
This test is run by defining duration in the setup object and evaluates how many times a test function can execute over the given time. More executions equal better performance.
Time taken for executions
This test is run be defining executions in the setup object and evaluates how long time it takes to execute a test function given times of executions. Less time equals better performance.
Example usage
This example tells executionerjs to run two different performance tests, one test which evaluates executions over time and one test that evaluates how long it takes to execute given executions. Note that the test functions are passed the executionerjs setup object so they can utilize static properties, in this case setup.array which is used in every test:
executioner({
array: new Array(100000),
duration: 500,
executions: 10000,
description: 'Javascript loop performance tests',
postContentLoaded: true,
test: {
'Traditional for loop, constant length':
function (setup) {
for (let i = 0, length = setup.array.lenght; i < length; i++) {}
},
'Traditional for loop, constant length, left hand operator':
function (setup) {
for (let i = 0, length = setup.array.lenght; i < length; ++i) {}
},
'Traditional for loop':
function (setup) {
for (let i = 0; i < setup.array.lenght; i++) {}
},
'Traditional for loop, left hand operator':
function (setup) {
for (let i = 0; i < setup.array.lenght; ++i) {}
},
'Array.prototype.forEach':
function (setup) {
setup.array.forEach(function () {});
}
}
});
This would print the following result in your browsers console:
executionerjs setup object
Required properties
test (object)
Is a key/value pair object that defines all tests that will be run during executionerjs performance testing.key (description): Description about the test
value (test function):
function (setup) {...}
Function that will be executed and tested. The test function will be passed the executionerjs setup object so it can utilize static properties/variables. This might give more accurate test results.
duration/executions (number)
It is required to define one of these and both can be defined at the same time.duration (number/ms):
Tells executionerjs to execute every test as many times as possible over given time (milliseconds).executions (number/times):
Tells executionerjs to execute every test given times.
Optional properties
description (string)
Overall description about what is being tested, defaults topostContentLoaded (bool)
If set totrue
all tests will run after DOM content is loaded, default value isundefined
Custom properties
The setup object accepts custom properties to be set. On every test execution the setup object is passed down to the test function so that it can utilize custom properties as static variables. This might result in more accurate test results in some cases. As seen in previous example the array property is used later in every defined test.