reatom_perf

node v14.20.1
version: master
endpointsharetweet
const { performance } = require("perf_hooks"); const ef = require("effector"); const w = require("wonka"); const { Action, Atom, createStore } = require("@reatom/core@2.0.0-alpha0"); const w_combine = (sourceA, sourceB) => { const source = w.combine(sourceA, sourceB); return w.pipe(source, w.sample(source)); }; const entry = Action(); const a = Atom(($, state = 0) => // $(state, entry, v => (v % 2 ? state : v + 1)), $(state, entry) ); const b = Atom(($) => $(a) + 1); const c = Atom(($) => $(a) + 1); const d = Atom(($) => $(b) + $(c)); const e = Atom(($) => $(d) + 1); const f = Atom(($) => $(d) + $(e)); const g = Atom(($) => $(d) + $(e)); const h = Atom(($) => $(f) + $(g)); const store = createStore(); let res = 0; store.subscribe(h, (v) => { res += v; }); const eEntry = ef.createEvent(); const eA = ef .createStore(0) // .on(eEntry, (state, v) => (v % 2 ? state : v + 1)) .on(eEntry, (state, v) => v); const eB = eA.map((a) => a + 1); const eC = eA.map((a) => a + 1); const eD = ef.combine(eB, eC, (b, c) => b + c); const eE = eD.map((d) => d + 1); const eF = ef.combine(eD, eE, (d, e) => d + e); const eG = ef.combine(eD, eE, (d, e) => d + e); const eH = ef.combine(eF, eG, (h1, h2) => h1 + h2); let eRes = 0; eH.subscribe((v) => { eRes += v; }); eRes = 0; const wEntry = w.makeSubject(); const wA = w.pipe( wEntry.source, w.map((v) => v) ); const wB = w.pipe( wA, w.map((v) => v + 1) ); const wC = w.pipe( wA, w.map((v) => v + 1) ); const wD = w.pipe( w_combine(wB, wC), w.map(([b, c]) => b + c) ); const wE = w.pipe( wD, w.map((v) => v + 1) ); const wF = w.pipe( w_combine(wD, wE), w.map(([d, e]) => d + e) ); const wG = w.pipe( w_combine(wD, wE), w.map(([d, e]) => d + e) ); const wH = w.pipe( w_combine(wF, wG), w.map(([h1, h2]) => h1 + h2) ); let wRes = 0; w.pipe( wH, w.subscribe((v) => { wRes += v; }) ); wRes = 0; const reatomLogs = []; const effectorLogs = []; const wonkaLogs = []; var i = 0; while (i++ < 1000) { const startReatom = performance.now(); store.dispatch(entry(i)); reatomLogs.push(performance.now() - startReatom); const startEffector = performance.now(); eEntry(i); effectorLogs.push(performance.now() - startEffector); const startWonka = performance.now(); wEntry.next(i); wonkaLogs.push(performance.now() - startWonka); } console.log({ res, eRes, wRes }); console.log("reatom", median(reatomLogs).toFixed(3)); console.log("effector", median(effectorLogs).toFixed(3)); console.log("wonka", median(wonkaLogs).toFixed(3)); function median(values) { if (values.length === 0) return 0; values = values.map((v) => +v); values.sort((a, b) => (a - b ? 1 : -1)); var half = Math.floor(values.length / 2); if (values.length % 2) return values[half]; return (values[half - 1] + values[half]) / 2.0; }
Loading…

no comments

    sign in to comment