Socket
Socket
Sign inDemoInstall

@codspeed/tinybench-plugin

Package Overview
Dependencies
10
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

2

dist/index.cjs.js

@@ -175,3 +175,3 @@ 'use strict';

bench.run = async () => {
console.log(`[CodSpeed] running with @codspeed/tinybench v${"1.0.0"}`);
console.log(`[CodSpeed] running with @codspeed/tinybench v${"1.0.1"}`);
for (const task of bench.tasks) {

@@ -178,0 +178,0 @@ const uri = callingFile + "::" + task.name;

@@ -173,3 +173,3 @@ import { measurement, initCore, optimizeFunction } from '@codspeed/core';

bench.run = async () => {
console.log(`[CodSpeed] running with @codspeed/tinybench v${"1.0.0"}`);
console.log(`[CodSpeed] running with @codspeed/tinybench v${"1.0.1"}`);
for (const task of bench.tasks) {

@@ -176,0 +176,0 @@ const uri = callingFile + "::" + task.name;

{
"name": "@codspeed/tinybench-plugin",
"version": "1.0.0",
"version": "1.0.1",
"description": "tinybench compatibility layer for CodSpeed",

@@ -18,3 +18,3 @@ "keywords": [

"author": "Arthur Pastel <arthur@codspeed.io>",
"repository": "https://github.com/CodSpeedHQ/codspeed-node/tree/main/packages/tinybench",
"repository": "https://github.com/CodSpeedHQ/codspeed-node",
"homepage": "https://codspeed.io",

@@ -25,10 +25,13 @@ "license": "Apache-2.0",

"@types/stack-trace": "^0.0.30",
"jest-mock-extended": "^3.0.1"
"jest-mock-extended": "^3.0.1",
"tinybench": "^2.3.0"
},
"dependencies": {
"@codspeed/core": "^1.0.0",
"@codspeed/core": "^1.0.1",
"find-up": "^6.3.0",
"stack-trace": "1.0.0-pre1",
"tinybench": "^2.3.1"
"stack-trace": "1.0.0-pre1"
},
"peerDependencies": {
"tinybench": "^2.3.0"
}
}
<div align="center">
<h1><code>@codspeed/tinybench</code></h1>
<h1><code>@codspeed/tinybench-plugin</code></h1>
tinybench compatibility layer for CodSpeed
[![CI](https://github.com/CodSpeedHQ/codspeed-node/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/codspeed-node/actions/workflows/ci.yml)
[![npm (scoped)](https://img.shields.io/npm/v/@codspeed/tinybench-plugin)](https://www.npmjs.com/package/@codspeed/tinybench-plugin)
[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)
</div>
## Documentation
Check out the [documentation](https://docs.codspeed.io/benchmarks/nodejs) for complete integration instructions.
## Installation
First install the plugin [`@codspeed/tinybench-plugin`](https://www.npmjs.com/package/@codspeed/tinybench-plugin) and `tinybench` (if not already installed):
```sh
npm install --save-dev @codspeed/tinybench-plugin tinybench
```
or with `yarn`:
```sh
yarn add --dev @codspeed/tinybench-plugin tinybench
```
or with `pnpm`:
```sh
pnpm add --save-dev @codspeed/tinybench-plugin tinybench
```
## Usage
Let's create a fibonacci function and benchmark it with tinybench and the CodSpeed plugin:
```js title="benches/bench.mjs"
import { Bench } from "tinybench";
import { withCodSpeed } from "@codspeed/tinybench-plugin";
function fibonacci(n) {
if (n < 2) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
const bench = withCodSpeed(new Bench());
bench
.add("fibonacci10", () => {
fibonacci(10);
})
.add("fibonacci15", () => {
fibonacci(15);
});
await bench.run();
console.table(
bench.tasks.map(({ name, result }) => ({
"Task Name": name,
"Average Time (ps)": result?.mean * 1000,
}))
);
```
Here, a few things are happening:
- We create a simple recursive fibonacci function.
- We create a new `Bench` instance with CodSpeed support by using the **`withCodSpeed`** helper. This step is **critical** to enable CodSpeed on your benchmarks.
- We add two benchmarks to the suite and launch it, benching our `fibonacci` function for 10 and 15.
Now, we can run our benchmarks locally to make sure everything is working as expected:
```sh
$ node benches/bench.mjs
[CodSpeed] 2 benches detected but no instrumentation found
[CodSpeed] falling back to tinybench
┌─────────┬───────────────┬────────────────────┐
│ (index) │ Task Name │ Average Time (ps) │
├─────────┼───────────────┼────────────────────┤
│ 0 │ 'fibonacci10' │ 0.5660083779532603 │
│ 1 │ 'fibonacci15' │ 5.2475729101797635 │
└─────────┴───────────────┴────────────────────┘
```
And... Congrats🎉, CodSpeed is installed in your benchmarking suite! Locally, CodSpeed will fallback to tinybench since the instrumentation is only available in the CI environment for now.
You can now [run those benchmark in your CI](https://docs.codspeed.io/benchmarks/nodejs#running-the-benchmarks-in-your-ci) to continuously get consistent performance measurements.
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc