squiggle/packages/squiggle-lang/scripts/bench-map-reduce.js

28 lines
562 B
JavaScript
Raw Normal View History

2022-09-10 17:01:04 +00:00
#!/usr/bin/env node
2022-09-15 11:17:19 +00:00
const s = require("@quri/squiggle-lang");
2022-09-10 17:01:04 +00:00
const measure = (cb, times = 1) => {
const t1 = new Date();
for (let i = 1; i <= times; i++) {
cb();
}
const t2 = new Date();
return (t2 - t1) / 1000;
};
2022-09-15 11:17:19 +00:00
const maxP = 5;
2022-09-10 17:01:04 +00:00
for (let p = 0; p <= maxP; p++) {
const size = Math.pow(10, p);
const prj = s.SqProject.create();
2022-09-15 11:17:19 +00:00
prj.setSource(
"main",
`List.upTo(1, ${size}) |> map({|x| List.upTo(1, 100) |> reduce(0, {|a,b|a+b})})`
);
2022-09-10 17:01:04 +00:00
const t = measure(() => {
2022-09-15 11:17:19 +00:00
prj.run("main");
2022-09-10 17:01:04 +00:00
});
console.log(`1e${p}`, "\t", t);
}