Async vs swc polyfill

Benchmark created on


Setup

async function get() {
	const a = await a1();
	const b = await b1();
	const c = await c1();

	return await d(a, b, c)
}

function asyncGeneratorStep(e, t, n, r, a, o, u) {
    try {
        var i = e[o](u);
        var c = i.value;
    } catch (e) {
        n(e);
        return;
    }
    if (i.done) {
        t(c);
    } else {
        Promise.resolve(c).then(r, a);
    }
}
function _async_to_generator(e) {
    return function() {
        var t = this, n = arguments;
        return new Promise(function(r, a) {
            var o = e.apply(t, n);
            function u(e) {
                asyncGeneratorStep(o, r, a, u, i, "next", e);
            }
            function i(e) {
                asyncGeneratorStep(o, r, a, u, i, "throw", e);
            }
            u(undefined);
        });
    };
}
function _ts_generator(e, t) {
    var n, r, a, o, u = {
        label: 0,
        sent: function() {
            if (a[0] & 1) throw a[1];
            return a[1];
        },
        trys: [],
        ops: []
    };
    return o = {
        next: i(0),
        "throw": i(1),
        "return": i(2)
    }, typeof Symbol === "function" && (o[Symbol.iterator] = function() {
        return this;
    }), o;
    function i(e) {
        return function(t) {
            return c([
                e,
                t
            ]);
        };
    }
    function c(o) {
        if (n) throw new TypeError("Generator is already executing.");
        while(u)try {
            if (n = 1, r && (a = o[0] & 2 ? r["return"] : o[0] ? r["throw"] || ((a = r["return"]) && a.call(r), 0) : r.next) && !(a = a.call(r, o[1])).done) return a;
            if (r = 0, a) o = [
                o[0] & 2,
                a.value
            ];
            switch(o[0]){
                case 0:
                case 1:
                    a = o;
                    break;
                case 4:
                    u.label++;
                    return {
                        value: o[1],
                        done: false
                    };
                case 5:
                    u.label++;
                    r = o[1];
                    o = [
                        0
                    ];
                    continue;
                case 7:
                    o = u.ops.pop();
                    u.trys.pop();
                    continue;
                default:
                    if (!(a = u.trys, a = a.length > 0 && a[a.length - 1]) && (o[0] === 6 || o[0] === 2)) {
                        u = 0;
                        continue;
                    }
                    if (o[0] === 3 && (!a || o[1] > a[0] && o[1] < a[3])) {
                        u.label = o[1];
                        break;
                    }
                    if (o[0] === 6 && u.label < a[1]) {
                        u.label = a[1];
                        a = o;
                        break;
                    }
                    if (a && u.label < a[2]) {
                        u.label = a[2];
                        u.ops.push(o);
                        break;
                    }
                    if (a[2]) u.ops.pop();
                    u.trys.pop();
                    continue;
            }
            o = t.call(e, u);
        } catch (e) {
            o = [
                6,
                e
            ];
            r = 0;
        } finally{
            n = a = 0;
        }
        if (o[0] & 5) throw o[1];
        return {
            value: o[0] ? o[1] : void 0,
            done: true
        };
    }
}
function get2() {
    return _get.apply(this, arguments);
}
function _get() {
    _get = _async_to_generator(function() {
        var e, t, n;
        return _ts_generator(this, function(r) {
            switch(r.label){
                case 0:
                    return [
                        4,
                        a1()
                    ];
                case 1:
                    e = r.sent();
                    return [
                        4,
                        b1()
                    ];
                case 2:
                    t = r.sent();
                    return [
                        4,
                        c1()
                    ];
                case 3:
                    n = r.sent();
                    return [
                        4,
                        d(e, t, n)
                    ];
                case 4:
                    return [
                        2,
                        r.sent()
                    ];
            }
        });
    });
    return _get.apply(this, arguments);
}

Test runner

Ready to run.

Testing in
TestOps/sec
async
get()
ready
polifill
get2()
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.