@codspeed/tinybench-plugin 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,6 +6,7 @@ tinybench compatibility layer for CodSpeed
6
6
  [![CI](https://github.com/CodSpeedHQ/codspeed-node/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/codspeed-node/actions/workflows/ci.yml)
7
7
  [![npm (scoped)](https://img.shields.io/npm/v/@codspeed/tinybench-plugin)](https://www.npmjs.com/package/@codspeed/tinybench-plugin)
8
8
  [![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)
9
+ [![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/codspeed-node)
9
10
 
10
11
  </div>
11
12
 
@@ -59,12 +60,7 @@ bench
59
60
  });
60
61
 
61
62
  await bench.run();
62
- console.table(
63
- bench.tasks.map(({ name, result }) => ({
64
- "Task Name": name,
65
- "Average Time (ps)": result?.mean * 1000,
66
- }))
67
- );
63
+ console.table(bench.table());
68
64
  ```
69
65
 
70
66
  Here, a few things are happening:
@@ -81,12 +77,12 @@ $ node benches/bench.mjs
81
77
  [CodSpeed] 2 benches detected but no instrumentation found
82
78
  [CodSpeed] falling back to tinybench
83
79
 
84
- ┌─────────┬───────────────┬────────────────────┐
85
- │ (index) │ Task Name │ Average Time (ps) │
86
- ├─────────┼───────────────┼────────────────────┤
87
- │ 0 │ 'fibonacci10' │ 0.5660083779532603 │
88
- │ 1 │ 'fibonacci15' │ 5.2475729101797635 │
89
- └─────────┴───────────────┴────────────────────┘
80
+ ┌─────────┬───────────────┬─────────────┬───────────────────┬──────────┬─────────┐
81
+ │ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
82
+ ├─────────┼───────────────┼─────────────┼───────────────────┼──────────┼─────────┤
83
+ │ 0 │ 'fibonacci10' │ '1,810,236' │ 552.4139857896414 │ '±0.18%' │ 905119 │
84
+ │ 1 │ 'fibonacci15' │ '177,516' │ 5633.276191749634 │ '±0.14%' │ 88759 │
85
+ └─────────┴───────────────┴─────────────┴───────────────────┴──────────┴─────────┘
90
86
  ```
91
87
 
92
88
  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.
package/dist/index.cjs.js CHANGED
@@ -1,112 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@codspeed/core');
4
- var path = require('node:path');
5
- var node_url = require('node:url');
6
- var process = require('node:process');
7
- var fs = require('node:fs');
8
- var path$1 = require('path');
4
+ var path = require('path');
9
5
  var url = require('url');
10
6
 
11
- const typeMappings = {
12
- directory: 'isDirectory',
13
- file: 'isFile',
14
- };
15
-
16
- function checkType(type) {
17
- if (Object.hasOwnProperty.call(typeMappings, type)) {
18
- return;
19
- }
20
-
21
- throw new Error(`Invalid type specified: ${type}`);
22
- }
23
-
24
- const matchType = (type, stat) => stat[typeMappings[type]]();
25
-
26
- const toPath$1 = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath;
27
-
28
- function locatePathSync(
29
- paths,
30
- {
31
- cwd = process.cwd(),
32
- type = 'file',
33
- allowSymlinks = true,
34
- } = {},
35
- ) {
36
- checkType(type);
37
- cwd = toPath$1(cwd);
38
-
39
- const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
40
-
41
- for (const path_ of paths) {
42
- try {
43
- const stat = statFunction(path.resolve(cwd, path_), {
44
- throwIfNoEntry: false,
45
- });
46
-
47
- if (!stat) {
48
- continue;
49
- }
50
-
51
- if (matchType(type, stat)) {
52
- return path_;
53
- }
54
- } catch {}
55
- }
56
- }
57
-
58
- const toPath = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath;
59
-
60
- const findUpStop = Symbol('findUpStop');
61
-
62
- function findUpMultipleSync(name, options = {}) {
63
- let directory = path.resolve(toPath(options.cwd) || '');
64
- const {root} = path.parse(directory);
65
- const stopAt = options.stopAt || root;
66
- const limit = options.limit || Number.POSITIVE_INFINITY;
67
- const paths = [name].flat();
68
-
69
- const runMatcher = locateOptions => {
70
- if (typeof name !== 'function') {
71
- return locatePathSync(paths, locateOptions);
72
- }
73
-
74
- const foundPath = name(locateOptions.cwd);
75
- if (typeof foundPath === 'string') {
76
- return locatePathSync([foundPath], locateOptions);
77
- }
78
-
79
- return foundPath;
80
- };
81
-
82
- const matches = [];
83
- // eslint-disable-next-line no-constant-condition
84
- while (true) {
85
- const foundPath = runMatcher({...options, cwd: directory});
86
-
87
- if (foundPath === findUpStop) {
88
- break;
89
- }
90
-
91
- if (foundPath) {
92
- matches.push(path.resolve(directory, foundPath));
93
- }
94
-
95
- if (directory === stopAt || matches.length >= limit) {
96
- break;
97
- }
98
-
99
- directory = path.dirname(directory);
100
- }
101
-
102
- return matches;
103
- }
104
-
105
- function findUpSync(name, options = {}) {
106
- const matches = findUpMultipleSync(name, {...options, limit: 1});
107
- return matches[0];
108
- }
109
-
110
7
  function get(belowFn) {
111
8
  const oldLimit = Error.stackTraceLimit;
112
9
  Error.stackTraceLimit = Infinity;
@@ -165,6 +62,7 @@ boolProperties.forEach(function (property) {
165
62
  };
166
63
  });
167
64
 
65
+ core.tryIntrospect();
168
66
  function isCodSpeedBenchOptions(options) {
169
67
  return "uri" in options;
170
68
  }
@@ -183,59 +81,48 @@ function withCodSpeed(bench) {
183
81
  bench.add = (name, fn, opts) => {
184
82
  const callingFile = getCallingFile();
185
83
  const uri = `${callingFile}::${name}`;
186
- const options = Object.assign({}, opts != null ? opts : {}, { uri });
84
+ const options = Object.assign({}, opts ?? {}, { uri });
187
85
  return rawAdd.bind(bench)(name, fn, options);
188
86
  };
189
87
  const rootCallingFile = getCallingFile();
190
88
  bench.run = async () => {
89
+ console.log(`[CodSpeed] running with @codspeed/tinybench v${"2.3.0"}`);
191
90
  core.setupCore();
192
- console.log(`[CodSpeed] running with @codspeed/tinybench v${"2.1.0"}`);
193
91
  for (const task of bench.tasks) {
194
- if (task.opts.beforeAll != null) {
195
- await task.opts.beforeAll.call(task);
196
- }
197
- if (task.opts.beforeEach != null) {
198
- await task.opts.beforeEach.call(task);
199
- }
200
92
  const uri = isCodSpeedBenchOptions(task.opts) ? task.opts.uri : `${rootCallingFile}::${task.name}`;
201
- await core.optimizeFunction(task.fn);
93
+ await task.opts.beforeAll?.call(task);
94
+ await core.optimizeFunction(async () => {
95
+ await task.opts.beforeEach?.call(task);
96
+ await task.fn();
97
+ await task.opts.afterEach?.call(task);
98
+ });
99
+ await task.opts.beforeEach?.call(task);
202
100
  await async function __codspeed_root_frame__() {
203
101
  core.Measurement.startInstrumentation();
204
102
  await task.fn();
205
103
  core.Measurement.stopInstrumentation(uri);
206
104
  }();
207
- if (task.opts.afterEach != null) {
208
- await task.opts.afterEach.call(task);
209
- }
210
- if (task.opts.afterAll != null) {
211
- await task.opts.afterAll.call(task);
212
- }
105
+ await task.opts.afterEach?.call(task);
106
+ await task.opts.afterAll?.call(task);
213
107
  console.log(` \u2714 Measured ${uri}`);
214
108
  }
109
+ core.teardownCore();
215
110
  console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
216
111
  return bench.tasks;
217
112
  };
218
- core.teardownCore();
219
113
  return bench;
220
114
  }
221
115
  function getCallingFile() {
222
116
  const stack = get();
223
117
  let callingFile = stack[2].getFileName();
224
- const gitDir = getGitDir(callingFile);
118
+ const gitDir = core.getGitDir(callingFile);
225
119
  if (gitDir === void 0) {
226
120
  throw new Error("Could not find a git repository");
227
121
  }
228
122
  if (callingFile.startsWith("file://")) {
229
123
  callingFile = url.fileURLToPath(callingFile);
230
124
  }
231
- return path$1.relative(gitDir, callingFile);
232
- }
233
- function getGitDir(path2) {
234
- const dotGitPath = findUpSync(".git", {
235
- cwd: path2,
236
- type: "directory"
237
- });
238
- return dotGitPath ? path$1.dirname(dotGitPath) : void 0;
125
+ return path.relative(gitDir, callingFile);
239
126
  }
240
127
 
241
128
  exports.withCodSpeed = withCodSpeed;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js","../../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js","../../../node_modules/.pnpm/stack-trace@1.0.0-pre2/node_modules/stack-trace/index.js","../src/index.ts"],"sourcesContent":["import process from 'node:process';\nimport path from 'node:path';\nimport fs, {promises as fsPromises} from 'node:fs';\nimport {fileURLToPath} from 'node:url';\nimport pLocate from 'p-locate';\n\nconst typeMappings = {\n\tdirectory: 'isDirectory',\n\tfile: 'isFile',\n};\n\nfunction checkType(type) {\n\tif (Object.hasOwnProperty.call(typeMappings, type)) {\n\t\treturn;\n\t}\n\n\tthrow new Error(`Invalid type specified: ${type}`);\n}\n\nconst matchType = (type, stat) => stat[typeMappings[type]]();\n\nconst toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\nexport async function locatePath(\n\tpaths,\n\t{\n\t\tcwd = process.cwd(),\n\t\ttype = 'file',\n\t\tallowSymlinks = true,\n\t\tconcurrency,\n\t\tpreserveOrder,\n\t} = {},\n) {\n\tcheckType(type);\n\tcwd = toPath(cwd);\n\n\tconst statFunction = allowSymlinks ? fsPromises.stat : fsPromises.lstat;\n\n\treturn pLocate(paths, async path_ => {\n\t\ttry {\n\t\t\tconst stat = await statFunction(path.resolve(cwd, path_));\n\t\t\treturn matchType(type, stat);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}, {concurrency, preserveOrder});\n}\n\nexport function locatePathSync(\n\tpaths,\n\t{\n\t\tcwd = process.cwd(),\n\t\ttype = 'file',\n\t\tallowSymlinks = true,\n\t} = {},\n) {\n\tcheckType(type);\n\tcwd = toPath(cwd);\n\n\tconst statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;\n\n\tfor (const path_ of paths) {\n\t\ttry {\n\t\t\tconst stat = statFunction(path.resolve(cwd, path_), {\n\t\t\t\tthrowIfNoEntry: false,\n\t\t\t});\n\n\t\t\tif (!stat) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (matchType(type, stat)) {\n\t\t\t\treturn path_;\n\t\t\t}\n\t\t} catch {}\n\t}\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {locatePath, locatePathSync} from 'locate-path';\n\nconst toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\nexport const findUpStop = Symbol('findUpStop');\n\nexport async function findUpMultiple(name, options = {}) {\n\tlet directory = path.resolve(toPath(options.cwd) || '');\n\tconst {root} = path.parse(directory);\n\tconst stopAt = path.resolve(directory, options.stopAt || root);\n\tconst limit = options.limit || Number.POSITIVE_INFINITY;\n\tconst paths = [name].flat();\n\n\tconst runMatcher = async locateOptions => {\n\t\tif (typeof name !== 'function') {\n\t\t\treturn locatePath(paths, locateOptions);\n\t\t}\n\n\t\tconst foundPath = await name(locateOptions.cwd);\n\t\tif (typeof foundPath === 'string') {\n\t\t\treturn locatePath([foundPath], locateOptions);\n\t\t}\n\n\t\treturn foundPath;\n\t};\n\n\tconst matches = [];\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\t// eslint-disable-next-line no-await-in-loop\n\t\tconst foundPath = await runMatcher({...options, cwd: directory});\n\n\t\tif (foundPath === findUpStop) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (foundPath) {\n\t\t\tmatches.push(path.resolve(directory, foundPath));\n\t\t}\n\n\t\tif (directory === stopAt || matches.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n\n\treturn matches;\n}\n\nexport function findUpMultipleSync(name, options = {}) {\n\tlet directory = path.resolve(toPath(options.cwd) || '');\n\tconst {root} = path.parse(directory);\n\tconst stopAt = options.stopAt || root;\n\tconst limit = options.limit || Number.POSITIVE_INFINITY;\n\tconst paths = [name].flat();\n\n\tconst runMatcher = locateOptions => {\n\t\tif (typeof name !== 'function') {\n\t\t\treturn locatePathSync(paths, locateOptions);\n\t\t}\n\n\t\tconst foundPath = name(locateOptions.cwd);\n\t\tif (typeof foundPath === 'string') {\n\t\t\treturn locatePathSync([foundPath], locateOptions);\n\t\t}\n\n\t\treturn foundPath;\n\t};\n\n\tconst matches = [];\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst foundPath = runMatcher({...options, cwd: directory});\n\n\t\tif (foundPath === findUpStop) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (foundPath) {\n\t\t\tmatches.push(path.resolve(directory, foundPath));\n\t\t}\n\n\t\tif (directory === stopAt || matches.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n\n\treturn matches;\n}\n\nexport async function findUp(name, options = {}) {\n\tconst matches = await findUpMultiple(name, {...options, limit: 1});\n\treturn matches[0];\n}\n\nexport function findUpSync(name, options = {}) {\n\tconst matches = findUpMultipleSync(name, {...options, limit: 1});\n\treturn matches[0];\n}\n\nexport {\n\tpathExists,\n\tpathExistsSync,\n} from 'path-exists';\n","export function get(belowFn) {\r\n const oldLimit = Error.stackTraceLimit;\r\n Error.stackTraceLimit = Infinity;\r\n\r\n const dummyObject = {};\r\n\r\n const v8Handler = Error.prepareStackTrace;\r\n Error.prepareStackTrace = function(dummyObject, v8StackTrace) {\r\n return v8StackTrace;\r\n };\r\n Error.captureStackTrace(dummyObject, belowFn || get);\r\n\r\n const v8StackTrace = dummyObject.stack;\r\n Error.prepareStackTrace = v8Handler;\r\n Error.stackTraceLimit = oldLimit;\r\n\r\n return v8StackTrace;\r\n}\r\n\r\nexport function parse(err) {\r\n if (!err.stack) {\r\n return [];\r\n }\r\n\r\n const lines = err.stack.split('\\n').slice(1);\r\n return lines\r\n .map(function(line) {\r\n if (line.match(/^\\s*[-]{4,}$/)) {\r\n return createParsedCallSite({\r\n fileName: line,\r\n lineNumber: null,\r\n functionName: null,\r\n typeName: null,\r\n methodName: null,\r\n columnNumber: null,\r\n 'native': null,\r\n });\r\n }\r\n\r\n const lineMatch = line.match(/at (?:(.+?)\\s+\\()?(?:(.+?):(\\d+)(?::(\\d+))?|([^)]+))\\)?/);\r\n if (!lineMatch) {\r\n return;\r\n }\r\n\r\n let object = null;\r\n let method = null;\r\n let functionName = null;\r\n let typeName = null;\r\n let methodName = null;\r\n let isNative = (lineMatch[5] === 'native');\r\n\r\n if (lineMatch[1]) {\r\n functionName = lineMatch[1];\r\n let methodStart = functionName.lastIndexOf('.');\r\n if (functionName[methodStart-1] == '.')\r\n methodStart--;\r\n if (methodStart > 0) {\r\n object = functionName.substr(0, methodStart);\r\n method = functionName.substr(methodStart + 1);\r\n const objectEnd = object.indexOf('.Module');\r\n if (objectEnd > 0) {\r\n functionName = functionName.substr(objectEnd + 1);\r\n object = object.substr(0, objectEnd);\r\n }\r\n }\r\n }\r\n\r\n if (method) {\r\n typeName = object;\r\n methodName = method;\r\n }\r\n\r\n if (method === '<anonymous>') {\r\n methodName = null;\r\n functionName = null;\r\n }\r\n\r\n const properties = {\r\n fileName: lineMatch[2] || null,\r\n lineNumber: parseInt(lineMatch[3], 10) || null,\r\n functionName: functionName,\r\n typeName: typeName,\r\n methodName: methodName,\r\n columnNumber: parseInt(lineMatch[4], 10) || null,\r\n 'native': isNative,\r\n };\r\n\r\n return createParsedCallSite(properties);\r\n })\r\n .filter(function(callSite) {\r\n return !!callSite;\r\n });\r\n}\r\n\r\nfunction CallSite(properties) {\r\n for (const property in properties) {\r\n this[property] = properties[property];\r\n }\r\n}\r\n\r\nconst strProperties = [\r\n 'this',\r\n 'typeName',\r\n 'functionName',\r\n 'methodName',\r\n 'fileName',\r\n 'lineNumber',\r\n 'columnNumber',\r\n 'function',\r\n 'evalOrigin'\r\n];\r\n\r\nconst boolProperties = [\r\n 'topLevel',\r\n 'eval',\r\n 'native',\r\n 'constructor'\r\n];\r\n\r\nstrProperties.forEach(function (property) {\r\n CallSite.prototype[property] = null;\r\n CallSite.prototype['get' + property[0].toUpperCase() + property.substr(1)] = function () {\r\n return this[property];\r\n }\r\n});\r\n\r\nboolProperties.forEach(function (property) {\r\n CallSite.prototype[property] = false;\r\n CallSite.prototype['is' + property[0].toUpperCase() + property.substr(1)] = function () {\r\n return this[property];\r\n }\r\n});\r\n\r\nfunction createParsedCallSite(properties) {\r\n return new CallSite(properties);\r\n}\r\n","import {\n Measurement,\n optimizeFunction,\n setupCore,\n teardownCore,\n} from \"@codspeed/core\";\nimport { findUpSync, Options } from \"find-up\";\nimport path, { dirname } from \"path\";\nimport { get as getStackTrace } from \"stack-trace\";\nimport { Bench, Task } from \"tinybench\";\nimport { fileURLToPath } from \"url\";\n\ndeclare const __VERSION__: string;\n\ntype CodSpeedBenchOptions = Task[\"opts\"] & {\n uri: string;\n};\n\nfunction isCodSpeedBenchOptions(\n options: Task[\"opts\"]\n): options is CodSpeedBenchOptions {\n return \"uri\" in options;\n}\n\nexport function withCodSpeed(bench: Bench): Bench {\n if (!Measurement.isInstrumented()) {\n const rawRun = bench.run;\n bench.run = async () => {\n console.warn(\n `[CodSpeed] ${bench.tasks.length} benches detected but no instrumentation found, falling back to tinybench`\n );\n return await rawRun.bind(bench)();\n };\n return bench;\n }\n\n const rawAdd = bench.add;\n bench.add = (name, fn, opts: CodSpeedBenchOptions) => {\n const callingFile = getCallingFile();\n const uri = `${callingFile}::${name}`;\n const options = Object.assign({}, opts ?? {}, { uri });\n return rawAdd.bind(bench)(name, fn, options);\n };\n const rootCallingFile = getCallingFile();\n\n bench.run = async () => {\n setupCore();\n console.log(`[CodSpeed] running with @codspeed/tinybench v${__VERSION__}`);\n for (const task of bench.tasks) {\n // run before hooks\n if (task.opts.beforeAll != null) {\n await task.opts.beforeAll.call(task);\n }\n if (task.opts.beforeEach != null) {\n await task.opts.beforeEach.call(task);\n }\n\n // run the actual benchmark, with instrumentation\n const uri = isCodSpeedBenchOptions(task.opts)\n ? task.opts.uri\n : `${rootCallingFile}::${task.name}`;\n await optimizeFunction(task.fn);\n await (async function __codspeed_root_frame__() {\n Measurement.startInstrumentation();\n await task.fn();\n Measurement.stopInstrumentation(uri);\n })();\n\n // run after hooks\n if (task.opts.afterEach != null) {\n await task.opts.afterEach.call(task);\n }\n if (task.opts.afterAll != null) {\n await task.opts.afterAll.call(task);\n }\n\n // print results\n console.log(` ✔ Measured ${uri}`);\n }\n console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);\n return bench.tasks;\n };\n teardownCore();\n return bench;\n}\n\nfunction getCallingFile(): string {\n const stack = getStackTrace();\n let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]\n const gitDir = getGitDir(callingFile);\n if (gitDir === undefined) {\n throw new Error(\"Could not find a git repository\");\n }\n if (callingFile.startsWith(\"file://\")) {\n callingFile = fileURLToPath(callingFile);\n }\n return path.relative(gitDir, callingFile);\n}\n\nfunction getGitDir(path: string): string | undefined {\n const dotGitPath = findUpSync(\".git\", {\n cwd: path,\n type: \"directory\",\n } as Options);\n return dotGitPath ? dirname(dotGitPath) : undefined;\n}\n"],"names":["toPath","fileURLToPath","Measurement","setupCore","optimizeFunction","teardownCore","getStackTrace","path","dirname"],"mappings":";;;;;;;;;;AAMA,MAAM,YAAY,GAAG;AACrB,CAAC,SAAS,EAAE,aAAa;AACzB,CAAC,IAAI,EAAE,QAAQ;AACf,CAAC,CAAC;AACF;AACA,SAAS,SAAS,CAAC,IAAI,EAAE;AACzB,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE;AACrD,EAAE,OAAO;AACT,EAAE;AACF;AACA,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AACD;AACA,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,YAAY,CA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KAAA,CAAA;AAAA,GACf,CAAA;AACA,EAAaG,iBAAA,EAAA,CAAA;AACb,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAEA,SAAS,cAAyB,GAAA;AAChC,EAAA,MAAM,QAAQC,GAAc,EAAA,CAAA;AAC5B,EAAA,IAAI,WAAc,GAAA,KAAA,CAAM,CAAC,CAAA,CAAE,WAAY,EAAA,CAAA;AACvC,EAAM,MAAA,MAAA,GAAS,UAAU,WAAW,CAAA,CAAA;AACpC,EAAA,IAAI,WAAW,KAAW,CAAA,EAAA;AACxB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA,CAAA;AAAA,GACnD;AACA,EAAI,IAAA,WAAA,CAAY,UAAW,CAAA,SAAS,CAAG,EAAA;AACrC,IAAA,WAAA,GAAcL,kBAAc,WAAW,CAAA,CAAA;AAAA,GACzC;AACA,EAAO,OAAAM,MAAA,CAAK,QAAS,CAAA,MAAA,EAAQ,WAAW,CAAA,CAAA;AAC1C,CAAA;AAEA,SAAS,UAAUA,KAAkC,EAAA;AACnD,EAAM,MAAA,UAAA,GAAa,WAAW,MAAQ,EAAA;AAAA,IACpC,GAAKA,EAAAA,KAAAA;AAAA,IACL,IAAM,EAAA,WAAA;AAAA,GACI,CAAA,CAAA;AACZ,EAAO,OAAA,UAAA,GAAaC,cAAQ,CAAA,UAAU,CAAI,GAAA,KAAA,CAAA,CAAA;AAC5C;;;;","x_google_ignoreList":[0,1,2]}
1
+ {"version":3,"file":"index.cjs.js","sources":["../../../node_modules/.pnpm/stack-trace@1.0.0-pre2/node_modules/stack-trace/index.js","../src/index.ts"],"sourcesContent":["export function get(belowFn) {\r\n const oldLimit = Error.stackTraceLimit;\r\n Error.stackTraceLimit = Infinity;\r\n\r\n const dummyObject = {};\r\n\r\n const v8Handler = Error.prepareStackTrace;\r\n Error.prepareStackTrace = function(dummyObject, v8StackTrace) {\r\n return v8StackTrace;\r\n };\r\n Error.captureStackTrace(dummyObject, belowFn || get);\r\n\r\n const v8StackTrace = dummyObject.stack;\r\n Error.prepareStackTrace = v8Handler;\r\n Error.stackTraceLimit = oldLimit;\r\n\r\n return v8StackTrace;\r\n}\r\n\r\nexport function parse(err) {\r\n if (!err.stack) {\r\n return [];\r\n }\r\n\r\n const lines = err.stack.split('\\n').slice(1);\r\n return lines\r\n .map(function(line) {\r\n if (line.match(/^\\s*[-]{4,}$/)) {\r\n return createParsedCallSite({\r\n fileName: line,\r\n lineNumber: null,\r\n functionName: null,\r\n typeName: null,\r\n methodName: null,\r\n columnNumber: null,\r\n 'native': null,\r\n });\r\n }\r\n\r\n const lineMatch = line.match(/at (?:(.+?)\\s+\\()?(?:(.+?):(\\d+)(?::(\\d+))?|([^)]+))\\)?/);\r\n if (!lineMatch) {\r\n return;\r\n }\r\n\r\n let object = null;\r\n let method = null;\r\n let functionName = null;\r\n let typeName = null;\r\n let methodName = null;\r\n let isNative = (lineMatch[5] === 'native');\r\n\r\n if (lineMatch[1]) {\r\n functionName = lineMatch[1];\r\n let methodStart = functionName.lastIndexOf('.');\r\n if (functionName[methodStart-1] == '.')\r\n methodStart--;\r\n if (methodStart > 0) {\r\n object = functionName.substr(0, methodStart);\r\n method = functionName.substr(methodStart + 1);\r\n const objectEnd = object.indexOf('.Module');\r\n if (objectEnd > 0) {\r\n functionName = functionName.substr(objectEnd + 1);\r\n object = object.substr(0, objectEnd);\r\n }\r\n }\r\n }\r\n\r\n if (method) {\r\n typeName = object;\r\n methodName = method;\r\n }\r\n\r\n if (method === '<anonymous>') {\r\n methodName = null;\r\n functionName = null;\r\n }\r\n\r\n const properties = {\r\n fileName: lineMatch[2] || null,\r\n lineNumber: parseInt(lineMatch[3], 10) || null,\r\n functionName: functionName,\r\n typeName: typeName,\r\n methodName: methodName,\r\n columnNumber: parseInt(lineMatch[4], 10) || null,\r\n 'native': isNative,\r\n };\r\n\r\n return createParsedCallSite(properties);\r\n })\r\n .filter(function(callSite) {\r\n return !!callSite;\r\n });\r\n}\r\n\r\nfunction CallSite(properties) {\r\n for (const property in properties) {\r\n this[property] = properties[property];\r\n }\r\n}\r\n\r\nconst strProperties = [\r\n 'this',\r\n 'typeName',\r\n 'functionName',\r\n 'methodName',\r\n 'fileName',\r\n 'lineNumber',\r\n 'columnNumber',\r\n 'function',\r\n 'evalOrigin'\r\n];\r\n\r\nconst boolProperties = [\r\n 'topLevel',\r\n 'eval',\r\n 'native',\r\n 'constructor'\r\n];\r\n\r\nstrProperties.forEach(function (property) {\r\n CallSite.prototype[property] = null;\r\n CallSite.prototype['get' + property[0].toUpperCase() + property.substr(1)] = function () {\r\n return this[property];\r\n }\r\n});\r\n\r\nboolProperties.forEach(function (property) {\r\n CallSite.prototype[property] = false;\r\n CallSite.prototype['is' + property[0].toUpperCase() + property.substr(1)] = function () {\r\n return this[property];\r\n }\r\n});\r\n\r\nfunction createParsedCallSite(properties) {\r\n return new CallSite(properties);\r\n}\r\n","import {\n getGitDir,\n Measurement,\n optimizeFunction,\n setupCore,\n teardownCore,\n tryIntrospect,\n} from \"@codspeed/core\";\nimport path from \"path\";\nimport { get as getStackTrace } from \"stack-trace\";\nimport { Bench, Task } from \"tinybench\";\nimport { fileURLToPath } from \"url\";\n\ndeclare const __VERSION__: string;\n\ntryIntrospect();\n\ntype CodSpeedBenchOptions = Task[\"opts\"] & {\n uri: string;\n};\n\nfunction isCodSpeedBenchOptions(\n options: Task[\"opts\"]\n): options is CodSpeedBenchOptions {\n return \"uri\" in options;\n}\n\nexport function withCodSpeed(bench: Bench): Bench {\n if (!Measurement.isInstrumented()) {\n const rawRun = bench.run;\n bench.run = async () => {\n console.warn(\n `[CodSpeed] ${bench.tasks.length} benches detected but no instrumentation found, falling back to tinybench`\n );\n return await rawRun.bind(bench)();\n };\n return bench;\n }\n\n const rawAdd = bench.add;\n bench.add = (name, fn, opts: CodSpeedBenchOptions) => {\n const callingFile = getCallingFile();\n const uri = `${callingFile}::${name}`;\n const options = Object.assign({}, opts ?? {}, { uri });\n return rawAdd.bind(bench)(name, fn, options);\n };\n const rootCallingFile = getCallingFile();\n\n bench.run = async () => {\n console.log(`[CodSpeed] running with @codspeed/tinybench v${__VERSION__}`);\n setupCore();\n for (const task of bench.tasks) {\n const uri = isCodSpeedBenchOptions(task.opts)\n ? task.opts.uri\n : `${rootCallingFile}::${task.name}`;\n\n await task.opts.beforeAll?.call(task);\n\n // run optimizations\n await optimizeFunction(async () => {\n await task.opts.beforeEach?.call(task);\n await task.fn();\n await task.opts.afterEach?.call(task);\n });\n\n // run instrumented benchmark\n await task.opts.beforeEach?.call(task);\n await (async function __codspeed_root_frame__() {\n Measurement.startInstrumentation();\n await task.fn();\n Measurement.stopInstrumentation(uri);\n })();\n await task.opts.afterEach?.call(task);\n\n await task.opts.afterAll?.call(task);\n\n // print results\n console.log(` ✔ Measured ${uri}`);\n }\n teardownCore();\n console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);\n return bench.tasks;\n };\n return bench;\n}\n\nfunction getCallingFile(): string {\n const stack = getStackTrace();\n let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]\n const gitDir = getGitDir(callingFile);\n if (gitDir === undefined) {\n throw new Error(\"Could not find a git repository\");\n }\n if (callingFile.startsWith(\"file://\")) {\n callingFile = fileURLToPath(callingFile);\n }\n return path.relative(gitDir, callingFile);\n}\n"],"names":["tryIntrospect","Measurement","setupCore","optimizeFunction","teardownCore","getStackTrace","getGitDir","fileURLToPath"],"mappings":";;;;;;AAAO,SAAS,GAAG,CAAC,OAAO,EAAE;AAC7B,EAAE,MAAM,QAAQ,GAAG,KAAK,CAAC,eAAe,CAAC;AACzC,EAAE,KAAK,CAAC,eAAe,GAAG,QAAQ,CAAC;AACnC;AACA,EAAE,MAAM,WAAW,GAAG,EAAE,CAAC;AACzB;AACA,EAAE,MAAM,SAAS,GAAG,KAAK,CAAC,iBAAiB,CAAC;AAC5C,EAAE,KAAK,CAAC,iBAAiB,GAAG,SAAS,WAAW,EAAE,YAAY,EAAE;AAChE,IAAI,OAAO,YAAY,CAAC;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AA;AAEpC,MAAA,MAAM,IAAK,CAAA,IAAA,CAAK,QAAU,EAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAGnC,MAAQ,OAAA,CAAA,GAAA,CAAI,uBAAkB,GAAK,CAAA,CAAA,CAAA,CAAA;AAAA,KACrC;AACA,IAAaG,iBAAA,EAAA,CAAA;AACb,IAAA,OAAA,CAAQ,GAAI,CAAA,CAAA,wBAAA,EAA2B,KAAM,CAAA,KAAA,CAAM,MAAiB,CAAA,SAAA,CAAA,CAAA,CAAA;AACpE,IAAA,OAAO,KAAM,CAAA,KAAA,CAAA;AAAA,GACf,CAAA;AACA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAEA,SAAS,cAAyB,GAAA;AAChC,EAAA,MAAM,QAAQC,GAAc,EAAA,CAAA;AAC5B,EAAA,IAAI,WAAc,GAAA,KAAA,CAAM,CAAC,CAAA,CAAE,WAAY,EAAA,CAAA;AACvC,EAAM,MAAA,MAAA,GAASC,eAAU,WAAW,CAAA,CAAA;AACpC,EAAA,IAAI,WAAW,KAAW,CAAA,EAAA;AACxB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA,CAAA;AAAA,GACnD;AACA,EAAI,IAAA,WAAA,CAAY,UAAW,CAAA,SAAS,CAAG,EAAA;AACrC,IAAA,WAAA,GAAcC,kBAAc,WAAW,CAAA,CAAA;AAAA,GACzC;AACA,EAAO,OAAA,IAAA,CAAK,QAAS,CAAA,MAAA,EAAQ,WAAW,CAAA,CAAA;AAC1C;;;;","x_google_ignoreList":[0]}
package/dist/index.es5.js CHANGED
@@ -1,109 +1,6 @@
1
- import { Measurement, setupCore, optimizeFunction, teardownCore } from '@codspeed/core';
2
- import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
- import process from 'node:process';
5
- import fs from 'node:fs';
6
- import path$1, { dirname } from 'path';
7
- import { fileURLToPath as fileURLToPath$1 } from 'url';
8
-
9
- const typeMappings = {
10
- directory: 'isDirectory',
11
- file: 'isFile',
12
- };
13
-
14
- function checkType(type) {
15
- if (Object.hasOwnProperty.call(typeMappings, type)) {
16
- return;
17
- }
18
-
19
- throw new Error(`Invalid type specified: ${type}`);
20
- }
21
-
22
- const matchType = (type, stat) => stat[typeMappings[type]]();
23
-
24
- const toPath$1 = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
25
-
26
- function locatePathSync(
27
- paths,
28
- {
29
- cwd = process.cwd(),
30
- type = 'file',
31
- allowSymlinks = true,
32
- } = {},
33
- ) {
34
- checkType(type);
35
- cwd = toPath$1(cwd);
36
-
37
- const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
38
-
39
- for (const path_ of paths) {
40
- try {
41
- const stat = statFunction(path.resolve(cwd, path_), {
42
- throwIfNoEntry: false,
43
- });
44
-
45
- if (!stat) {
46
- continue;
47
- }
48
-
49
- if (matchType(type, stat)) {
50
- return path_;
51
- }
52
- } catch {}
53
- }
54
- }
55
-
56
- const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
57
-
58
- const findUpStop = Symbol('findUpStop');
59
-
60
- function findUpMultipleSync(name, options = {}) {
61
- let directory = path.resolve(toPath(options.cwd) || '');
62
- const {root} = path.parse(directory);
63
- const stopAt = options.stopAt || root;
64
- const limit = options.limit || Number.POSITIVE_INFINITY;
65
- const paths = [name].flat();
66
-
67
- const runMatcher = locateOptions => {
68
- if (typeof name !== 'function') {
69
- return locatePathSync(paths, locateOptions);
70
- }
71
-
72
- const foundPath = name(locateOptions.cwd);
73
- if (typeof foundPath === 'string') {
74
- return locatePathSync([foundPath], locateOptions);
75
- }
76
-
77
- return foundPath;
78
- };
79
-
80
- const matches = [];
81
- // eslint-disable-next-line no-constant-condition
82
- while (true) {
83
- const foundPath = runMatcher({...options, cwd: directory});
84
-
85
- if (foundPath === findUpStop) {
86
- break;
87
- }
88
-
89
- if (foundPath) {
90
- matches.push(path.resolve(directory, foundPath));
91
- }
92
-
93
- if (directory === stopAt || matches.length >= limit) {
94
- break;
95
- }
96
-
97
- directory = path.dirname(directory);
98
- }
99
-
100
- return matches;
101
- }
102
-
103
- function findUpSync(name, options = {}) {
104
- const matches = findUpMultipleSync(name, {...options, limit: 1});
105
- return matches[0];
106
- }
1
+ import { tryIntrospect, Measurement, setupCore, optimizeFunction, teardownCore, getGitDir } from '@codspeed/core';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
107
4
 
108
5
  function get(belowFn) {
109
6
  const oldLimit = Error.stackTraceLimit;
@@ -163,6 +60,7 @@ boolProperties.forEach(function (property) {
163
60
  };
164
61
  });
165
62
 
63
+ tryIntrospect();
166
64
  function isCodSpeedBenchOptions(options) {
167
65
  return "uri" in options;
168
66
  }
@@ -181,39 +79,35 @@ function withCodSpeed(bench) {
181
79
  bench.add = (name, fn, opts) => {
182
80
  const callingFile = getCallingFile();
183
81
  const uri = `${callingFile}::${name}`;
184
- const options = Object.assign({}, opts != null ? opts : {}, { uri });
82
+ const options = Object.assign({}, opts ?? {}, { uri });
185
83
  return rawAdd.bind(bench)(name, fn, options);
186
84
  };
187
85
  const rootCallingFile = getCallingFile();
188
86
  bench.run = async () => {
87
+ console.log(`[CodSpeed] running with @codspeed/tinybench v${"2.3.0"}`);
189
88
  setupCore();
190
- console.log(`[CodSpeed] running with @codspeed/tinybench v${"2.1.0"}`);
191
89
  for (const task of bench.tasks) {
192
- if (task.opts.beforeAll != null) {
193
- await task.opts.beforeAll.call(task);
194
- }
195
- if (task.opts.beforeEach != null) {
196
- await task.opts.beforeEach.call(task);
197
- }
198
90
  const uri = isCodSpeedBenchOptions(task.opts) ? task.opts.uri : `${rootCallingFile}::${task.name}`;
199
- await optimizeFunction(task.fn);
91
+ await task.opts.beforeAll?.call(task);
92
+ await optimizeFunction(async () => {
93
+ await task.opts.beforeEach?.call(task);
94
+ await task.fn();
95
+ await task.opts.afterEach?.call(task);
96
+ });
97
+ await task.opts.beforeEach?.call(task);
200
98
  await async function __codspeed_root_frame__() {
201
99
  Measurement.startInstrumentation();
202
100
  await task.fn();
203
101
  Measurement.stopInstrumentation(uri);
204
102
  }();
205
- if (task.opts.afterEach != null) {
206
- await task.opts.afterEach.call(task);
207
- }
208
- if (task.opts.afterAll != null) {
209
- await task.opts.afterAll.call(task);
210
- }
103
+ await task.opts.afterEach?.call(task);
104
+ await task.opts.afterAll?.call(task);
211
105
  console.log(` \u2714 Measured ${uri}`);
212
106
  }
107
+ teardownCore();
213
108
  console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
214
109
  return bench.tasks;
215
110
  };
216
- teardownCore();
217
111
  return bench;
218
112
  }
219
113
  function getCallingFile() {
@@ -224,16 +118,9 @@ function getCallingFile() {
224
118
  throw new Error("Could not find a git repository");
225
119
  }
226
120
  if (callingFile.startsWith("file://")) {
227
- callingFile = fileURLToPath$1(callingFile);
121
+ callingFile = fileURLToPath(callingFile);
228
122
  }
229
- return path$1.relative(gitDir, callingFile);
230
- }
231
- function getGitDir(path2) {
232
- const dotGitPath = findUpSync(".git", {
233
- cwd: path2,
234
- type: "directory"
235
- });
236
- return dotGitPath ? dirname(dotGitPath) : void 0;
123
+ return path.relative(gitDir, callingFile);
237
124
  }
238
125
 
239
126
  export { withCodSpeed };
@@ -1 +1 @@
1
- {"version":3,"file":"index.es5.js","sources":["../../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js","../../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js","../../../node_modules/.pnpm/stack-trace@1.0.0-pre2/node_modules/stack-trace/index.js","../src/index.ts"],"sourcesContent":["import process from 'node:process';\nimport path from 'node:path';\nimport fs, {promises as fsPromises} from 'node:fs';\nimport {fileURLToPath} from 'node:url';\nimport pLocate from 'p-locate';\n\nconst typeMappings = {\n\tdirectory: 'isDirectory',\n\tfile: 'isFile',\n};\n\nfunction checkType(type) {\n\tif (Object.hasOwnProperty.call(typeMappings, type)) {\n\t\treturn;\n\t}\n\n\tthrow new Error(`Invalid type specified: ${type}`);\n}\n\nconst matchType = (type, stat) => stat[typeMappings[type]]();\n\nconst toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\nexport async function locatePath(\n\tpaths,\n\t{\n\t\tcwd = process.cwd(),\n\t\ttype = 'file',\n\t\tallowSymlinks = true,\n\t\tconcurrency,\n\t\tpreserveOrder,\n\t} = {},\n) {\n\tcheckType(type);\n\tcwd = toPath(cwd);\n\n\tconst statFunction = allowSymlinks ? fsPromises.stat : fsPromises.lstat;\n\n\treturn pLocate(paths, async path_ => {\n\t\ttry {\n\t\t\tconst stat = await statFunction(path.resolve(cwd, path_));\n\t\t\treturn matchType(type, stat);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}, {concurrency, preserveOrder});\n}\n\nexport function locatePathSync(\n\tpaths,\n\t{\n\t\tcwd = process.cwd(),\n\t\ttype = 'file',\n\t\tallowSymlinks = true,\n\t} = {},\n) {\n\tcheckType(type);\n\tcwd = toPath(cwd);\n\n\tconst statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;\n\n\tfor (const path_ of paths) {\n\t\ttry {\n\t\t\tconst stat = statFunction(path.resolve(cwd, path_), {\n\t\t\t\tthrowIfNoEntry: false,\n\t\t\t});\n\n\t\t\tif (!stat) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (matchType(type, stat)) {\n\t\t\t\treturn path_;\n\t\t\t}\n\t\t} catch {}\n\t}\n}\n","import path from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {locatePath, locatePathSync} from 'locate-path';\n\nconst toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;\n\nexport const findUpStop = Symbol('findUpStop');\n\nexport async function findUpMultiple(name, options = {}) {\n\tlet directory = path.resolve(toPath(options.cwd) || '');\n\tconst {root} = path.parse(directory);\n\tconst stopAt = path.resolve(directory, options.stopAt || root);\n\tconst limit = options.limit || Number.POSITIVE_INFINITY;\n\tconst paths = [name].flat();\n\n\tconst runMatcher = async locateOptions => {\n\t\tif (typeof name !== 'function') {\n\t\t\treturn locatePath(paths, locateOptions);\n\t\t}\n\n\t\tconst foundPath = await name(locateOptions.cwd);\n\t\tif (typeof foundPath === 'string') {\n\t\t\treturn locatePath([foundPath], locateOptions);\n\t\t}\n\n\t\treturn foundPath;\n\t};\n\n\tconst matches = [];\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\t// eslint-disable-next-line no-await-in-loop\n\t\tconst foundPath = await runMatcher({...options, cwd: directory});\n\n\t\tif (foundPath === findUpStop) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (foundPath) {\n\t\t\tmatches.push(path.resolve(directory, foundPath));\n\t\t}\n\n\t\tif (directory === stopAt || matches.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n\n\treturn matches;\n}\n\nexport function findUpMultipleSync(name, options = {}) {\n\tlet directory = path.resolve(toPath(options.cwd) || '');\n\tconst {root} = path.parse(directory);\n\tconst stopAt = options.stopAt || root;\n\tconst limit = options.limit || Number.POSITIVE_INFINITY;\n\tconst paths = [name].flat();\n\n\tconst runMatcher = locateOptions => {\n\t\tif (typeof name !== 'function') {\n\t\t\treturn locatePathSync(paths, locateOptions);\n\t\t}\n\n\t\tconst foundPath = name(locateOptions.cwd);\n\t\tif (typeof foundPath === 'string') {\n\t\t\treturn locatePathSync([foundPath], locateOptions);\n\t\t}\n\n\t\treturn foundPath;\n\t};\n\n\tconst matches = [];\n\t// eslint-disable-next-line no-constant-condition\n\twhile (true) {\n\t\tconst foundPath = runMatcher({...options, cwd: directory});\n\n\t\tif (foundPath === findUpStop) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (foundPath) {\n\t\t\tmatches.push(path.resolve(directory, foundPath));\n\t\t}\n\n\t\tif (directory === stopAt || matches.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\n\t\tdirectory = path.dirname(directory);\n\t}\n\n\treturn matches;\n}\n\nexport async function findUp(name, options = {}) {\n\tconst matches = await findUpMultiple(name, {...options, limit: 1});\n\treturn matches[0];\n}\n\nexport function findUpSync(name, options = {}) {\n\tconst matches = findUpMultipleSync(name, {...options, limit: 1});\n\treturn matches[0];\n}\n\nexport {\n\tpathExists,\n\tpathExistsSync,\n} from 'path-exists';\n","export function get(belowFn) {\r\n const oldLimit = Error.stackTraceLimit;\r\n Error.stackTraceLimit = Infinity;\r\n\r\n const dummyObject = {};\r\n\r\n const v8Handler = Error.prepareStackTrace;\r\n Error.prepareStackTrace = function(dummyObject, v8StackTrace) {\r\n return v8StackTrace;\r\n };\r\n Error.captureStackTrace(dummyObject, belowFn || get);\r\n\r\n const v8StackTrace = dummyObject.stack;\r\n Error.prepareStackTrace = v8Handler;\r\n Error.stackTraceLimit = oldLimit;\r\n\r\n return v8StackTrace;\r\n}\r\n\r\nexport function parse(err) {\r\n if (!err.stack) {\r\n return [];\r\n }\r\n\r\n const lines = err.stack.split('\\n').slice(1);\r\n return lines\r\n .map(function(line) {\r\n if (line.match(/^\\s*[-]{4,}$/)) {\r\n return createParsedCallSite({\r\n fileName: line,\r\n lineNumber: null,\r\n functionName: null,\r\n typeName: null,\r\n methodName: null,\r\n columnNumber: null,\r\n 'native': null,\r\n });\r\n }\r\n\r\n const lineMatch = line.match(/at (?:(.+?)\\s+\\()?(?:(.+?):(\\d+)(?::(\\d+))?|([^)]+))\\)?/);\r\n if (!lineMatch) {\r\n return;\r\n }\r\n\r\n let object = null;\r\n let method = null;\r\n let functionName = null;\r\n let typeName = null;\r\n let methodName = null;\r\n let isNative = (lineMatch[5] === 'native');\r\n\r\n if (lineMatch[1]) {\r\n functionName = lineMatch[1];\r\n let methodStart = functionName.lastIndexOf('.');\r\n if (functionName[methodStart-1] == '.')\r\n methodStart--;\r\n if (methodStart > 0) {\r\n object = functionName.substr(0, methodStart);\r\n method = functionName.substr(methodStart + 1);\r\n const objectEnd = object.indexOf('.Module');\r\n if (objectEnd > 0) {\r\n functionName = functionName.substr(objectEnd + 1);\r\n object = object.substr(0, objectEnd);\r\n }\r\n }\r\n }\r\n\r\n if (method) {\r\n typeName = object;\r\n methodName = method;\r\n }\r\n\r\n if (method === '<anonymous>') {\r\n methodName = null;\r\n functionName = null;\r\n }\r\n\r\n const properties = {\r\n fileName: lineMatch[2] || null,\r\n lineNumber: parseInt(lineMatch[3], 10) || null,\r\n functionName: functionName,\r\n typeName: typeName,\r\n methodName: methodName,\r\n columnNumber: parseInt(lineMatch[4], 10) || null,\r\n 'native': isNative,\r\n };\r\n\r\n return createParsedCallSite(properties);\r\n })\r\n .filter(function(callSite) {\r\n return !!callSite;\r\n });\r\n}\r\n\r\nfunction CallSite(properties) {\r\n for (const property in properties) {\r\n this[property] = properties[property];\r\n }\r\n}\r\n\r\nconst strProperties = [\r\n 'this',\r\n 'typeName',\r\n 'functionName',\r\n 'methodName',\r\n 'fileName',\r\n 'lineNumber',\r\n 'columnNumber',\r\n 'function',\r\n 'evalOrigin'\r\n];\r\n\r\nconst boolProperties = [\r\n 'topLevel',\r\n 'eval',\r\n 'native',\r\n 'constructor'\r\n];\r\n\r\nstrProperties.forEach(function (property) {\r\n CallSite.prototype[property] = null;\r\n CallSite.prototype['get' + property[0].toUpperCase() + property.substr(1)] = function () {\r\n return this[property];\r\n }\r\n});\r\n\r\nboolProperties.forEach(function (property) {\r\n CallSite.prototype[property] = false;\r\n CallSite.prototype['is' + property[0].toUpperCase() + property.substr(1)] = function () {\r\n return this[property];\r\n }\r\n});\r\n\r\nfunction createParsedCallSite(properties) {\r\n return new CallSite(properties);\r\n}\r\n","import {\n Measurement,\n optimizeFunction,\n setupCore,\n teardownCore,\n} from \"@codspeed/core\";\nimport { findUpSync, Options } from \"find-up\";\nimport path, { dirname } from \"path\";\nimport { get as getStackTrace } from \"stack-trace\";\nimport { Bench, Task } from \"tinybench\";\nimport { fileURLToPath } from \"url\";\n\ndeclare const __VERSION__: string;\n\ntype CodSpeedBenchOptions = Task[\"opts\"] & {\n uri: string;\n};\n\nfunction isCodSpeedBenchOptions(\n options: Task[\"opts\"]\n): options is CodSpeedBenchOptions {\n return \"uri\" in options;\n}\n\nexport function withCodSpeed(bench: Bench): Bench {\n if (!Measurement.isInstrumented()) {\n const rawRun = bench.run;\n bench.run = async () => {\n console.warn(\n `[CodSpeed] ${bench.tasks.length} benches detected but no instrumentation found, falling back to tinybench`\n );\n return await rawRun.bind(bench)();\n };\n return bench;\n }\n\n const rawAdd = bench.add;\n bench.add = (name, fn, opts: CodSpeedBenchOptions) => {\n const callingFile = getCallingFile();\n const uri = `${callingFile}::${name}`;\n const options = Object.assign({}, opts ?? {}, { uri });\n return rawAdd.bind(bench)(name, fn, options);\n };\n const rootCallingFile = getCallingFile();\n\n bench.run = async () => {\n setupCore();\n console.log(`[CodSpeed] running with @codspeed/tinybench v${__VERSION__}`);\n for (const task of bench.tasks) {\n // run before hooks\n if (task.opts.beforeAll != null) {\n await task.opts.beforeAll.call(task);\n }\n if (task.opts.beforeEach != null) {\n await task.opts.beforeEach.call(task);\n }\n\n // run the actual benchmark, with instrumentation\n const uri = isCodSpeedBenchOptions(task.opts)\n ? task.opts.uri\n : `${rootCallingFile}::${task.name}`;\n await optimizeFunction(task.fn);\n await (async function __codspeed_root_frame__() {\n Measurement.startInstrumentation();\n await task.fn();\n Measurement.stopInstrumentation(uri);\n })();\n\n // run after hooks\n if (task.opts.afterEach != null) {\n await task.opts.afterEach.call(task);\n }\n if (task.opts.afterAll != null) {\n await task.opts.afterAll.call(task);\n }\n\n // print results\n console.log(` ✔ Measured ${uri}`);\n }\n console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);\n return bench.tasks;\n };\n teardownCore();\n return bench;\n}\n\nfunction getCallingFile(): string {\n const stack = getStackTrace();\n let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]\n const gitDir = getGitDir(callingFile);\n if (gitDir === undefined) {\n throw new Error(\"Could not find a git repository\");\n }\n if (callingFile.startsWith(\"file://\")) {\n callingFile = fileURLToPath(callingFile);\n }\n return path.relative(gitDir, callingFile);\n}\n\nfunction getGitDir(path: string): string | undefined {\n const dotGitPath = findUpSync(\".git\", {\n cwd: path,\n type: \"directory\",\n } as Options);\n return dotGitPath ? dirname(dotGitPath) : undefined;\n}\n"],"names":["toPath","getStackTrace","fileURLToPath","path"],"mappings":";;;;;;;;AAMA,MAAM,YAAY,GAAG;AACrB,CAAC,SAAS,EAAE,aAAa;AACzB,CAAC,IAAI,EAAE,QAAQ;AACf,CAAC,CAAC;AACF;AACA,SAAS,SAAS,CAAC,IAAI,EAAE;AACzB,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE;AACrD,EAAE,OAAO;AACT,EAAE;AACF;AACA,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AACD;AACA,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;AAC7D;AACA,MAAMA,QAAM,GAAG,SAAS,IAAI,SAAS,YAAY,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AA0B5F;AACO,SAAS,cAAc;AAC9B,CAAC,KAAK;AACN,CAAC;AACD,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;AACrB,EAAE,IAAI,GAAG,MAAM;AACf,EAAE,aAAa,GAAG,IAAI;AACtB,EAAE,GAAG,EAAE;AACP,EAAE;AACF,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC,GAAG,GAAGA,QAAM,CAAC,GAAG,CAAC,CAAC;AACnB;AACA,CAAC,MAAM,YAAY,GAAG,aAAa,GAAG,EAAE,CAAC,QAAQ,GAAG,EAAE,CAAC,SAAS,CAAC;AACjE;AACA,CAAC,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE;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;AAC1C,CAAA;AAEA,SAAS,UAAUA,KAAkC,EAAA;AACnD,EAAM,MAAA,UAAA,GAAa,WAAW,MAAQ,EAAA;AAAA,IACpC,GAAKA,EAAAA,KAAAA;AAAA,IACL,IAAM,EAAA,WAAA;AAAA,GACI,CAAA,CAAA;AACZ,EAAO,OAAA,UAAA,GAAa,OAAQ,CAAA,UAAU,CAAI,GAAA,KAAA,CAAA,CAAA;AAC5C;;;;","x_google_ignoreList":[0,1,2]}
1
+ {"version":3,"file":"index.es5.js","sources":["../../../node_modules/.pnpm/stack-trace@1.0.0-pre2/node_modules/stack-trace/index.js","../src/index.ts"],"sourcesContent":["export function get(belowFn) {\r\n const oldLimit = Error.stackTraceLimit;\r\n Error.stackTraceLimit = Infinity;\r\n\r\n const dummyObject = {};\r\n\r\n const v8Handler = Error.prepareStackTrace;\r\n Error.prepareStackTrace = function(dummyObject, v8StackTrace) {\r\n return v8StackTrace;\r\n };\r\n Error.captureStackTrace(dummyObject, belowFn || get);\r\n\r\n const v8StackTrace = dummyObject.stack;\r\n Error.prepareStackTrace = v8Handler;\r\n Error.stackTraceLimit = oldLimit;\r\n\r\n return v8StackTrace;\r\n}\r\n\r\nexport function parse(err) {\r\n if (!err.stack) {\r\n return [];\r\n }\r\n\r\n const lines = err.stack.split('\\n').slice(1);\r\n return lines\r\n .map(function(line) {\r\n if (line.match(/^\\s*[-]{4,}$/)) {\r\n return createParsedCallSite({\r\n fileName: line,\r\n lineNumber: null,\r\n functionName: null,\r\n typeName: null,\r\n methodName: null,\r\n columnNumber: null,\r\n 'native': null,\r\n });\r\n }\r\n\r\n const lineMatch = line.match(/at (?:(.+?)\\s+\\()?(?:(.+?):(\\d+)(?::(\\d+))?|([^)]+))\\)?/);\r\n if (!lineMatch) {\r\n return;\r\n }\r\n\r\n let object = null;\r\n let method = null;\r\n let functionName = null;\r\n let typeName = null;\r\n let methodName = null;\r\n let isNative = (lineMatch[5] === 'native');\r\n\r\n if (lineMatch[1]) {\r\n functionName = lineMatch[1];\r\n let methodStart = functionName.lastIndexOf('.');\r\n if (functionName[methodStart-1] == '.')\r\n methodStart--;\r\n if (methodStart > 0) {\r\n object = functionName.substr(0, methodStart);\r\n method = functionName.substr(methodStart + 1);\r\n const objectEnd = object.indexOf('.Module');\r\n if (objectEnd > 0) {\r\n functionName = functionName.substr(objectEnd + 1);\r\n object = object.substr(0, objectEnd);\r\n }\r\n }\r\n }\r\n\r\n if (method) {\r\n typeName = object;\r\n methodName = method;\r\n }\r\n\r\n if (method === '<anonymous>') {\r\n methodName = null;\r\n functionName = null;\r\n }\r\n\r\n const properties = {\r\n fileName: lineMatch[2] || null,\r\n lineNumber: parseInt(lineMatch[3], 10) || null,\r\n functionName: functionName,\r\n typeName: typeName,\r\n methodName: methodName,\r\n columnNumber: parseInt(lineMatch[4], 10) || null,\r\n 'native': isNative,\r\n };\r\n\r\n return createParsedCallSite(properties);\r\n })\r\n .filter(function(callSite) {\r\n return !!callSite;\r\n });\r\n}\r\n\r\nfunction CallSite(properties) {\r\n for (const property in properties) {\r\n this[property] = properties[property];\r\n }\r\n}\r\n\r\nconst strProperties = [\r\n 'this',\r\n 'typeName',\r\n 'functionName',\r\n 'methodName',\r\n 'fileName',\r\n 'lineNumber',\r\n 'columnNumber',\r\n 'function',\r\n 'evalOrigin'\r\n];\r\n\r\nconst boolProperties = [\r\n 'topLevel',\r\n 'eval',\r\n 'native',\r\n 'constructor'\r\n];\r\n\r\nstrProperties.forEach(function (property) {\r\n CallSite.prototype[property] = null;\r\n CallSite.prototype['get' + property[0].toUpperCase() + property.substr(1)] = function () {\r\n return this[property];\r\n }\r\n});\r\n\r\nboolProperties.forEach(function (property) {\r\n CallSite.prototype[property] = false;\r\n CallSite.prototype['is' + property[0].toUpperCase() + property.substr(1)] = function () {\r\n return this[property];\r\n }\r\n});\r\n\r\nfunction createParsedCallSite(properties) {\r\n return new CallSite(properties);\r\n}\r\n","import {\n getGitDir,\n Measurement,\n optimizeFunction,\n setupCore,\n teardownCore,\n tryIntrospect,\n} from \"@codspeed/core\";\nimport path from \"path\";\nimport { get as getStackTrace } from \"stack-trace\";\nimport { Bench, Task } from \"tinybench\";\nimport { fileURLToPath } from \"url\";\n\ndeclare const __VERSION__: string;\n\ntryIntrospect();\n\ntype CodSpeedBenchOptions = Task[\"opts\"] & {\n uri: string;\n};\n\nfunction isCodSpeedBenchOptions(\n options: Task[\"opts\"]\n): options is CodSpeedBenchOptions {\n return \"uri\" in options;\n}\n\nexport function withCodSpeed(bench: Bench): Bench {\n if (!Measurement.isInstrumented()) {\n const rawRun = bench.run;\n bench.run = async () => {\n console.warn(\n `[CodSpeed] ${bench.tasks.length} benches detected but no instrumentation found, falling back to tinybench`\n );\n return await rawRun.bind(bench)();\n };\n return bench;\n }\n\n const rawAdd = bench.add;\n bench.add = (name, fn, opts: CodSpeedBenchOptions) => {\n const callingFile = getCallingFile();\n const uri = `${callingFile}::${name}`;\n const options = Object.assign({}, opts ?? {}, { uri });\n return rawAdd.bind(bench)(name, fn, options);\n };\n const rootCallingFile = getCallingFile();\n\n bench.run = async () => {\n console.log(`[CodSpeed] running with @codspeed/tinybench v${__VERSION__}`);\n setupCore();\n for (const task of bench.tasks) {\n const uri = isCodSpeedBenchOptions(task.opts)\n ? task.opts.uri\n : `${rootCallingFile}::${task.name}`;\n\n await task.opts.beforeAll?.call(task);\n\n // run optimizations\n await optimizeFunction(async () => {\n await task.opts.beforeEach?.call(task);\n await task.fn();\n await task.opts.afterEach?.call(task);\n });\n\n // run instrumented benchmark\n await task.opts.beforeEach?.call(task);\n await (async function __codspeed_root_frame__() {\n Measurement.startInstrumentation();\n await task.fn();\n Measurement.stopInstrumentation(uri);\n })();\n await task.opts.afterEach?.call(task);\n\n await task.opts.afterAll?.call(task);\n\n // print results\n console.log(` ✔ Measured ${uri}`);\n }\n teardownCore();\n console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);\n return bench.tasks;\n };\n return bench;\n}\n\nfunction getCallingFile(): string {\n const stack = getStackTrace();\n let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]\n const gitDir = getGitDir(callingFile);\n if (gitDir === undefined) {\n throw new Error(\"Could not find a git repository\");\n }\n if (callingFile.startsWith(\"file://\")) {\n callingFile = fileURLToPath(callingFile);\n }\n return path.relative(gitDir, callingFile);\n}\n"],"names":["getStackTrace"],"mappings":";;;;AAAO,SAAS,GAAG,CAAC,OAAO,EAAE;AAC7B,EAAE,MAAM,QAAQ,GAAG,KAAK,CAAC,eAAe,CAAC;AACzC,EAAE,KAAK,CAAC,eAAe,GAAG,QAAQ,CAAC;AACnC;AACA,EAAE,MAAM,WAAW,GAAG,EAAE,CAAC;AACzB;AACA,EAAE,MAAM,SAAS,GAAG,KAAK,CAAC,iBAAiB,CAAC;AAC5C,EAAE,KAAK,CAAC,iBAAiB,GAAG,SAAS,WAAW,EAAE,YAAY,EAAE;AAChE,IAAI,OAAO,YAAY,CAAC;AACxB,GAAG,CAAC;AACJ,EAAE,KAAK,CAAC,iBAAiB,CAAC,WAAW,EAAE,OAAO,IAAI,GAAG,CAAC,CAAC;AACvD;AACA,EAAE,MAAM,YAAY,GAAG,WAAW,CAAC,KAAK,CAAC;AACzC,EAAE,KAAK,CAAC,iBAAiB,GAAG,SAAS,CAAC;AACtC,EAAE,KAAK,CAAC,eAAe,GAAG,QAAQ,CAAC;AACnC;AACA,EAAE,OAAO,YAAY,CAAC;AACtB,CAAC;AA4ED;AACA,SAAS,QAAQ,CAAC,UAAU,EAAE;AAC9B,EAAE,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;AACrC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC1C,GAAG;AACH,CAAC;AACD;AACA,MAAM,aAAa,GAAG;AACtB,EAAE,MAAM;AACR,EAAE,UAAU;AACZ,EAAE,cAAc;AAChB,EAAE,YAAY;AACd,EAAE,UAAU;AACZ,EAAE,YAAY;AACd,EAAE,cAAc;AAChB,EAAE,U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B,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA,CAAA;AAAA,GACnD;AACA,EAAI,IAAA,WAAA,CAAY,UAAW,CAAA,SAAS,CAAG,EAAA;AACrC,IAAA,WAAA,GAAc,cAAc,WAAW,CAAA,CAAA;AAAA,GACzC;AACA,EAAO,OAAA,IAAA,CAAK,QAAS,CAAA,MAAA,EAAQ,WAAW,CAAA,CAAA;AAC1C;;;;","x_google_ignoreList":[0]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codspeed/tinybench-plugin",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "tinybench compatibility layer for CodSpeed",
5
5
  "keywords": [
6
6
  "codspeed",
@@ -19,14 +19,12 @@
19
19
  "homepage": "https://codspeed.io",
20
20
  "license": "Apache-2.0",
21
21
  "devDependencies": {
22
- "@types/find-up": "^4.0.0",
23
22
  "@types/stack-trace": "^0.0.30",
24
23
  "jest-mock-extended": "^3.0.4",
25
- "tinybench": "^2.4.0"
24
+ "tinybench": "^2.5.0"
26
25
  },
27
26
  "dependencies": {
28
- "@codspeed/core": "^2.1.0",
29
- "find-up": "^6.3.0",
27
+ "@codspeed/core": "^2.3.0",
30
28
  "stack-trace": "1.0.0-pre2"
31
29
  },
32
30
  "peerDependencies": {