Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add oby to benchmark #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions bench/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as Sjs from 's-js';
import * as solid from './solid-js-baseline.js';
import * as preact from '@preact/signals-core';
import * as maverick from '../dist/prod/index.js';
import oby from 'oby';
import Table from 'cli-table';

const BATCHED = true;
Expand Down Expand Up @@ -39,6 +40,7 @@ async function main() {
report.maverick = { fn: runMaverick, runs: [], avg: [] };
report.S = { fn: runS, runs: [] };
report.solid = { fn: runSolid, runs: [] };
report.oby = { fn: runOby, runs: [] };

// Has no way to dispose so can't consider it feature comparable.
// report.reactively = { fn: runReactively, runs: [], avg: [] };
Expand Down Expand Up @@ -356,4 +358,44 @@ function runCellx(layers, done) {
done(isSolution(layers, solution) ? endTime : -1);
}

/**
* @see {@link https://github.com/vobyjs/oby}
*/
function runOby(layers, done) {
const a = oby(1);
const b = oby(2);
const c = oby(3);
const d = oby(4);

const start = { a, b, c, d };

let layer = start;

for (let i = layers; i--; ) {
layer = ((m) => {
const props = {
a: oby.memo(() => m.b()),
b: oby.memo(() => m.a() - m.c()),
c: oby.memo(() => m.b() + m.d()),
d: oby.memo(() => m.c()),
};

return props;
})(layer);
}

const startTime = performance.now();

const run = BATCHED ? oby.batch : (fn) => fn();
run(() => {
a(4), b(3), c(2), d(1);
});

const end = layer;
const solution = [end.a(), end.b(), end.c(), end.d()];
const endTime = performance.now() - startTime;

done(isSolution(layers, solution) ? endTime : -1);
}

main();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"cellx": "^1.10.26",
"cli-table": "^0.3.11",
"kleur": "^4.1.5",
"oby": "^13.1.4",
"prettier": "^2.8.0",
"rimraf": "^3.0.2",
"s-js": "^0.4.9",
Expand Down