Skip to content

liriliri/eruda-benchmark

Repository files navigation

eruda-benchmark

NPM version License

Eruda plugin for running JavaScript benchmarks.

Demo

Browse it on your phone: http://eruda.liriliri.io/?plugin=benchmark

Install

npm install eruda-benchmark --save
eruda.add(erudaBenchmark);

Make sure Eruda is loaded before this plugin, otherwise won't work.

Usage

After initialization:

var benchmark = eruda.get('benchmark');

benchmark.add('Test', function () 
{
    var arr = new Array(10000); 
    for (var i = 0; i < 10000; i++) arr[i] = i * 2;
});
benchmark.add('Test Suite', [
    {
        name: 'RegExp#test',
        fn: function () 
        {
            /o/.test('Hello World!');
        }
    },
    {
        name: 'String#indexOf',
        fn: function () 
        {
            'Hello World!'.indexOf('o') > -1;
        }
    },
    {
        name: 'String#match',
        fn: function ()
        {
            !!'Hello World!'.match(/o/);
        }
    }
]);