Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bunchmark/core

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bunchmark/core - npm Package Compare versions

Comparing version 1.0.0-pre-1 to 1.0.0-pre-10

index.js

2

core.js
export {run} from "./src/run.js"
export {compiler} from "./src/compile.js"
export {compiler, bake} from "./src/compile.js"
{
"name": "@bunchmark/core",
"version": "1.0.0-pre-1",
"version": "1.0.0-pre-10",
"description": "benchmarking lib",

@@ -19,3 +19,6 @@ "type": "module",

},
"homepage": "https://github.com/pygy/bunchmark.js#readme"
"homepage": "https://github.com/pygy/bunchmark.js#readme",
"dependencies": {
"@bunchmark/stats": "1.0.0-pre-5"
}
}

@@ -35,10 +35,7 @@ // @ts-check

const randStr = () => (Math.random() * 0x7fffffff | 0).toString(36);
const uid = [randStr(), randStr(), randStr(), randStr()].join("_");
const result_uid = `result_${uid}`;
const now_id = `now_${uid}`;
const uid = () => [randStr(), randStr(), randStr(), randStr()].join("_");
const hasPerf = typeof performance !== "undefined";
const header = `
const ${result_uid} = [];
const ${now_id} = ${hasPerf ? "() => performance.now()" : "process.hrtime.bigint"}
`;
// .now() is a method, it needs a performance object as this
const getTime = hasPerf ? "() => performance.now()" : "process.hrtime.bigint"
/**

@@ -52,11 +49,14 @@ * @param {string} result_uid

const N = "N_" + uid;
/**
* @param {Task} task // TODO find a way to use {Task} instead of {object}
* @param {Task} task
* @param {Code} beforeEach
* @param {Code} afterEach
* @param {string} now_id
* @param {string} result_uid
* @returns {string}
*/
const bakeTask = ({ run, before = "", after = "" }, beforeEach, afterEach) => `
const bakeTask = ({ run, before = "", after = "" }, beforeEach, afterEach, now_id, result_uid) => {
const N = "N_" + uid()
return `
${result_uid}.push(async function(${N}){

@@ -74,5 +74,4 @@ ${stringify({ beforeEach })};

});
`;
`};
/**

@@ -82,10 +81,14 @@ * @param {Bakable} bakable

*/
function bake({ tasks, preamble = "", beforeEach = "", afterEach = "", header, footer }) {
return `
function bake({ tasks, preamble = "", beforeEach = "", afterEach = "", footer }) {
const result_uid = `result_${uid()}`
const now_id = `now_${uid()}`
return `
globalThis.result = void setTimeout(()=>{console.log(result)}, 2**31 - 1);
${stringify({ preamble })};
${header};
const ${result_uid} = []
const ${now_id} = ${getTime}
${tasks.map((task) => bakeTask(task, beforeEach, afterEach, now_id, result_uid)).join("")}
${tasks.map(task => bakeTask(task, beforeEach, afterEach)).join("")}
${footer(result_uid)}

@@ -100,3 +103,3 @@ `;

function compiler({ tasks, preamble = "", beforeEach = "", afterEach = "" }) {
const source = bake({ tasks, preamble, beforeEach, afterEach, header, footer });
const source = bake({ tasks, preamble, beforeEach, afterEach, footer });
/**

@@ -103,0 +106,0 @@ * @type {Sampler[]} samplers

@@ -21,3 +21,3 @@ export { run };

import { shuffled } from "./shuffle.js";
import { median } from "../../stats/stats.js";
import { median } from "@bunchmark/stats";

@@ -71,4 +71,2 @@ const {ceil} = Math

const { sample, result, result: { workspace, chronological, calibration }, keepChrono } = task;
if (typeof sample !== 'function')
debugger;
let N = 1;

@@ -108,3 +106,3 @@ for (;;) {

const reps = ceil(N * jitterFactor)
const t = await sample(reps) / reps;
const t = (await sample(reps)) / reps;
result.workspace.push(t);

@@ -115,3 +113,2 @@ if (keepChrono)

/**

@@ -134,3 +131,3 @@ * @param {RunnerOptions} options

for (const task of tasks) {
findN(task, calibrationTargetDuration);
yield { kind: "task", task: findN(task, calibrationTargetDuration) };
}

@@ -174,6 +171,6 @@ }

* @param {Options} options
* @param {((o:Options)=>Sampler[])} compiler
* @returns {Promise<Result>}
*/
async function run(options) {
const {compiler = (await import("./compile.js")).compiler} = options

@@ -228,4 +225,6 @@ const samplers = await compiler(options);

reject(e);
return;
}
if (status == null) throw new TypeError("Unexpected null") // TS flow analysis is lacking here
// appease TypeScript, this can't ever be null
if (status == null) throw new TypeError("Unexpected null")
if (!status.done) {

@@ -232,0 +231,0 @@ if (!isTick(status))

@@ -0,1 +1,4 @@

// This can be useful:
// https://alexharri.com/blog/jsdoc-as-an-alternative-typescript-syntax
export type Sampler = ((N: number)=>Promise<number>)

@@ -8,3 +11,2 @@

afterEach: Code,
header: string,
footer: (id: string)=> string

@@ -15,7 +17,8 @@ }

export type Task = {
name?: string
before?: Code
after?: Code
run: Code
export type Entry = {
name?: string,
workspace: number[],
chronological: number[],
calibration: number[],
N: number
}

@@ -32,10 +35,2 @@

export type Entry = {
name?: string,
workspace: number[],
chronological: number[],
calibration: number[],
N: number
}
export type Options = {

@@ -51,6 +46,14 @@ preamble?: Code,

handle?: {}
compiler?: (o:Options)=>Sampler[]
compiler?: (o:Options)=>(Promise<Sampler[]>|Sampler[])
onTick?: (t: Result)=>void
}
export type Result = {
i: number,
reps: number,
entries: Entry[]
}
export type ReturnTick = {i: number, reps: number}
export type RunnerOptions = {

@@ -70,16 +73,18 @@ tasks: InnerTask[],

export type Result = {
i: number,
reps: number,
entries: Entry[]
export type RunResult = {
result: Promise<Result>,
pause: (mode?: boolean) => void
stop: () => void
}
export type Task = {
name?: string
before?: Code
after?: Code
run: Code
}
export type YieldTask = {kind: "task", task: Promise<void>}
export type YieldTick = {kind: "tick", i: number, reps: number}
export type ReturnTick = {i: number, reps: number}
export type RunResult = {
result: Promise<Result>,
pause: (mode?: boolean) => void
stop: () => void
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc