Skip to content

A library for JavaScript performance testing.

License

GPL-2.0, MIT licenses found

Licenses found

GPL-2.0
GPL-LICENSE.txt
MIT
MIT-LICENSE.txt
Notifications You must be signed in to change notification settings

colinbdclark/sheep.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sheep.js: JavaScript Performance Benchmarking

Sheep.js is a simple tool for running performance tests in the browser.

Examples

Test a simple function:

sheep.test({
    name: "How fast is Math.random()?",
    test: Math.random
});

Test a function with arguments:

sheep.test({
    name: "How fast is Math.round()?",
    test: function() {
        Math.round(27.443);
    }
});

Test a method on an object:

sheep.test({
    name: "How fast Array.length?",
    
    // The setup function is called once per test sequence.
    setup: function () {
        return [1, 2, 3, 4, 5];
    },
    
    // The test function is passed the return value of the setup function each time.
    test: function (arr) {
        arr.length();
    }
});

Run several tests:

sheep.test([
    {
        name: "How fast is the Math.random?",
        test: Math.random
    },
    
    {
        name: "How fast Array.length?",
        
        // The setup function is called once per test sequence.
        setup: function () {
            return [1, 2, 3, 4, 5];
        },
        
        // The test function is passed the return value of the setup function each time.
        test: function (arr) {
            arr.length();
        }
    }
]);

All options:

sheep.test({
    name: "How fast Array.length?",
    
    numReps: 10, // Defaults to 100000
    
    // The setup function is called once per test sequence.
    setup: function () {
        return [1, 2, 3, 4, 5];
    },
    
    // The test function is passed the return value of the setup function each time.
    test: function (arr) {
        arr.length();
    },
    
    // onSuccess is called at the end of each test sequence, and is passed the timing data.
    onSuccess: function (timing) {
        console.log("The test for Array.length() just finished and it took " +
            timing.total + "ms to run the test " + timing.runs + " times.");
    }
});

Sheep.js was written by Colin Clark, and is distributed under the MIT and GPL licenses.

About

A library for JavaScript performance testing.

Resources

License

GPL-2.0, MIT licenses found

Licenses found

GPL-2.0
GPL-LICENSE.txt
MIT
MIT-LICENSE.txt

Stars

Watchers

Forks

Releases

No releases published

Packages