time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

bench-sampleset-to-pointset.ts (920B)


      1 #!/usr/bin/env node
      2 import { SqProject } from "../index.js";
      3 import { measure } from "../cli/utils.js";
      4 
      5 const maxP = 4;
      6 
      7 const sampleCount = process.env["SAMPLE_COUNT"];
      8 
      9 async function main() {
     10   for (let p = 0; p <= maxP; p++) {
     11     const size = Math.pow(10, p);
     12     const project = SqProject.create();
     13     if (sampleCount) {
     14       project.setEnvironment({
     15         sampleCount: Number(sampleCount),
     16         xyPointLength: Number(sampleCount),
     17       });
     18     }
     19     project.setSource(
     20       "main",
     21       `
     22     List.upTo(1, ${size}) -> map(
     23       { |x| normal(x,2) -> SampleSet.fromDist -> PointSet.fromDist }
     24     )->List.last
     25     `
     26     );
     27     const time = await measure(async () => {
     28       await project.run("main");
     29     });
     30     const result = project.getResult("main");
     31     if (!result.ok) {
     32       throw new Error("Code failed: " + result.value.toString());
     33     }
     34     console.log(`1e${p}`, "\t", time);
     35   }
     36 }
     37 
     38 main();