1.0.1 • Published 4 years ago

asyncmark v1.0.1

Weekly downloads
22
License
MIT
Repository
github
Last release
4 years ago

AsyncMark

A benchmarking library for javascript that supports Promise.

NPM

Test Status Test Coverage Maintainability

dependencies Status devDependencies Status optionalDependencies Status

license docs

You can try benchmark on the web.

be simple

import { Benchmark } from 'asyncmark';


new Benchmark(function() {
    return new Promise((resolve, reject) => {
        setTimeout(resolve, 100);
    });
}).run().catch(console.error);

be customizable

import { Suite } from 'asyncmark';


const suite = new Suite({
    name: 'ways to find a character',
    beforeEach() {
        this.text = 'hello world';
    },
    parallel: true,
});

suite.add(function() {
    /o/.test(this.text);
});

suite.add({
    name: 'String#indexOf',
    before() {
        console.log('starting String#indexOf...');
    },
    fun() {
        this.text.indexOf('o') > -1;
    },
});

suite.add(new Benchmark({
    name: 'String#match',
    fun() {
        Boolean(this.text.match(/o/));
    },
    after(result) {
        console.log('String#match is done! ' + result);
    },
}));

suite.run()
    .then(results => {
        let min = results[0];
        results.forEach(x => {
            if (min.average > x.average) {
                min = x;
            }
        });
        console.log(min.name + ' is best way!');
    })
    .catch(err => console.error(err));

with unit test

import { Benchmark } from 'asyncmark';


describe('benchmark test', function() {
    it('foobar', async function() {
        const result = await new Benchmark(function() {
            # do_something
        }).run();

        result.assert("<100ms");  # expect faster than 100ms.
    });
});

installation

Node.js

$ npm install asyncmark

ES6

import { Benchmark, Suite } from 'asyncmark';

CommonJS

const AsyncMark = require('asyncmark');

const Benchmark = AsyncMark.Benchmark;
const Suite = AsyncMark.Suite;

Browser

<script src="https://unpkg.com/asyncmark"></script>
<script>
const Benchmark = AsyncMark.Benchmark;
const Suite = AsyncMark.Suite;
</script>
1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-dev.0

4 years ago

1.0.0-dev.1

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.4

5 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.0

6 years ago