Socket
Socket
Sign inDemoInstall

cronometro

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cronometro - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

### 2020-09-18 / 0.5.0
- feat: Add setup option to prepare tests.
### 2020-04-22 / 0.4.0

@@ -2,0 +6,0 @@

@@ -63,2 +63,3 @@ 'use strict';

worker_threads_1.workerData.tests = Object.entries(tests);
worker_threads_1.workerData.setup = options && typeof options !== 'function' && options.setup ? options.setup : {};
return;

@@ -65,0 +66,0 @@ }

@@ -9,2 +9,5 @@ "use strict";

}
function noSetup(cb) {
cb();
}
function handleTestIteration(context, error) {

@@ -89,6 +92,24 @@ // Grab duration even in case of error to make sure we don't add any overhead to the benchmark

}
function afterSetup(testContext, err) {
if (err) {
return testContext.callback({
success: false,
error: err,
size: 0,
min: 0,
max: 0,
mean: 0,
stddev: 0,
percentiles: {},
standardError: 0
});
}
// Schedule the first run
return process.nextTick(() => runTestIteration(testContext));
}
function runWorker(context, notifier, cb) {
const { warmup, tests, index, iterations, errorThreshold } = context;
const { warmup, tests, index, iterations, errorThreshold, setup } = context;
// Require the original file to build tests
const [name, test] = tests[index];
const testSetup = typeof setup[name] === 'function' ? setup[name] : noSetup;
// Prepare the context

@@ -121,5 +142,9 @@ const testContext = {

testContext.handler = handleTestIteration.bind(null, testContext);
// Schedule the first run
process.nextTick(() => runTestIteration(testContext));
// Run the test setup, then start the test
const callback = afterSetup.bind(null, testContext);
const testSetupResponse = testSetup(callback);
if (testSetupResponse && typeof testSetupResponse.then === 'function') {
testSetupResponse.then(callback, callback);
}
}
exports.runWorker = runWorker;

2

package.json
{
"name": "cronometro",
"version": "0.4.0",
"version": "0.5.0",
"description": "Simple benchmarking suite powered by HDR histograms.",

@@ -5,0 +5,0 @@ "homepage": "https://sw.cowtech.it/cronometro",

@@ -58,2 +58,3 @@ # cronometro

- `setup`: An object whose properties names are the same as the test and values are setup functions. The functions will be run before the test. Both async/promise and callback style functions are accepted.
- `iterations`: The number of iterations to run for each test. Must be a positive number. The default is `10000`.

@@ -131,3 +132,10 @@ - `errorThreshold`: If active, it stops the test run before the desider number of iterations if the standard error is below the provided value and at least 10% of the iterations have been run. Must be a number between `0` (which disables this option) and `100`. The default is `1`.

},
{ print: { compare: true } },
{
setup: {
single(cb) {
cb()
}
},
print: { compare: true }
},
(err, results) => {

@@ -134,0 +142,0 @@ if (err) {

@@ -7,4 +7,8 @@ import { AbstractHistogram } from 'hdr-histogram-js';

}
export declare type SetupFunction = (cb: (err?: Error | null) => void) => Promise<any> | void;
export interface Options {
iterations: number;
setup: {
[key: string]: SetupFunction;
};
errorThreshold: number;

@@ -18,3 +22,3 @@ print: boolean | PrintOptions;

export declare type Test = StaticTest | AsyncTest | PromiseTest;
export declare type Callback = ((err: Error | null) => any) | ((err: null, results: Results) => any);
export declare type Callback = ((err: Error | null) => void) | ((err: null, results: Results) => any);
export interface Percentiles {

@@ -53,2 +57,5 @@ [key: string]: number;

tests: Array<[string, Test]>;
setup: {
[key: string]: SetupFunction;
};
index: number;

@@ -55,0 +62,0 @@ iterations: number;

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