-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add examples and run them in the ci
- Loading branch information
1 parent
25b5247
commit 056eef2
Showing
16 changed files
with
2,695 additions
and
5,445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { withCodSpeed } = require("@codspeed/benchmark.js-plugin"); | ||
const Benchmark = require("benchmark"); | ||
|
||
const suite = withCodSpeed(new Benchmark.Suite()); | ||
|
||
suite | ||
.add("RegExp#test", function () { | ||
/o/.test("Hello World!"); | ||
}) | ||
.add("String#indexOf", function () { | ||
"Hello World!".indexOf("o") > -1; | ||
}) | ||
// add listeners | ||
.on("cycle", function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
// run async | ||
.run({ async: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "with-javascript-cjs", | ||
"private": true, | ||
"scripts": { | ||
"bench-benchmark-js": "node benchmark-js.js", | ||
"bench-tinybench": "node tinybench.js" | ||
}, | ||
"devDependencies": { | ||
"@codspeed/benchmark.js-plugin": "workspace:^1.1.0", | ||
"@codspeed/tinybench-plugin": "workspace:^1.1.0", | ||
"benchmark": "^2.1.4", | ||
"tinybench": "^2.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { withCodSpeed } = require("@codspeed/tinybench-plugin"); | ||
const { Bench } = require("tinybench"); | ||
|
||
const bench = withCodSpeed(new Bench({ time: 100 })); | ||
|
||
bench | ||
.add("switch 1", () => { | ||
let a = 1; | ||
let b = 2; | ||
const c = a; | ||
a = b; | ||
b = c; | ||
}) | ||
.add("switch 2", () => { | ||
let a = 1; | ||
let b = 10; | ||
a = b + a; | ||
b = a - b; | ||
a = b - a; | ||
}); | ||
|
||
bench.run().then(() => { | ||
console.table( | ||
bench.tasks.map(({ name, result }) => ({ | ||
"Task Name": name, | ||
"Average Time (ps)": result?.mean ? result.mean * 1000 : "N/A", | ||
"Variance (ps)": result?.variance ? result.variance * 1000 : "N/A", | ||
})) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { withCodSpeed } from "@codspeed/benchmark.js-plugin"; | ||
import Benchmark from "benchmark"; | ||
|
||
const suite = withCodSpeed(new Benchmark.Suite()); | ||
|
||
suite | ||
.add("RegExp#test", function () { | ||
/o/.test("Hello World!"); | ||
}) | ||
.add("String#indexOf", function () { | ||
"Hello World!".indexOf("o") > -1; | ||
}) | ||
// add listeners | ||
.on("cycle", function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
// run async | ||
.run({ async: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "with-javascript-esm", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"bench-benchmark-js": "node benchmark-js.js", | ||
"bench-tinybench": "node tinybench.js" | ||
}, | ||
"devDependencies": { | ||
"@codspeed/benchmark.js-plugin": "workspace:^1.1.0", | ||
"@codspeed/tinybench-plugin": "workspace:^1.1.0", | ||
"benchmark": "^2.1.4", | ||
"tinybench": "^2.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { withCodSpeed } from "@codspeed/tinybench-plugin"; | ||
import { Bench } from "tinybench"; | ||
|
||
const bench = withCodSpeed(new Bench({ time: 100 })); | ||
|
||
bench | ||
.add("switch 1", () => { | ||
let a = 1; | ||
let b = 2; | ||
const c = a; | ||
a = b; | ||
b = c; | ||
}) | ||
.add("switch 2", () => { | ||
let a = 1; | ||
let b = 10; | ||
a = b + a; | ||
b = a - b; | ||
a = b - a; | ||
}); | ||
|
||
bench.run().then(() => { | ||
console.table( | ||
bench.tasks.map(({ name, result }) => ({ | ||
"Task Name": name, | ||
"Average Time (ps)": result?.mean ? result.mean * 1000 : "N/A", | ||
"Variance (ps)": result?.variance ? result.variance * 1000 : "N/A", | ||
})) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { withCodSpeed } from "@codspeed/benchmark.js-plugin"; | ||
import Benchmark from "benchmark"; | ||
|
||
const suite = withCodSpeed(new Benchmark.Suite()); | ||
|
||
suite | ||
.add("RegExp#test", function () { | ||
/o/.test("Hello World!"); | ||
}) | ||
.add("String#indexOf", function () { | ||
"Hello World!".indexOf("o") > -1; | ||
}) | ||
// add listeners | ||
.on("cycle", function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
// run async | ||
.run({ async: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "with-typescript-module", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"bench-benchmark-js": "node --loader esbuild-register/loader -r esbuild-register benchmark-js.ts", | ||
"bench-tinybench": "node --loader esbuild-register/loader -r esbuild-register tinybench.ts" | ||
}, | ||
"devDependencies": { | ||
"@codspeed/benchmark.js-plugin": "workspace:^1.1.0", | ||
"@codspeed/tinybench-plugin": "workspace:^1.1.0", | ||
"benchmark": "^2.1.4", | ||
"esbuild-register": "^3.4.2", | ||
"tinybench": "^2.5.0", | ||
"typescript": "^5.1.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { withCodSpeed } from "@codspeed/tinybench-plugin"; | ||
import { Bench } from "tinybench"; | ||
|
||
const bench = withCodSpeed(new Bench({ time: 100 })); | ||
|
||
bench | ||
.add("switch 1", () => { | ||
let a = 1; | ||
let b = 2; | ||
const c = a; | ||
a = b; | ||
b = c; | ||
}) | ||
.add("switch 2", () => { | ||
let a = 1; | ||
let b = 10; | ||
a = b + a; | ||
b = a - b; | ||
a = b - a; | ||
}); | ||
|
||
bench.run().then(() => { | ||
console.table( | ||
bench.tasks.map(({ name, result }) => ({ | ||
"Task Name": name, | ||
"Average Time (ps)": result?.mean ? result.mean * 1000 : "N/A", | ||
"Variance (ps)": result?.variance ? result.variance * 1000 : "N/A", | ||
})) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { withCodSpeed } from "@codspeed/benchmark.js-plugin"; | ||
import Benchmark from "benchmark"; | ||
|
||
const suite = withCodSpeed(new Benchmark.Suite()); | ||
|
||
suite | ||
.add("RegExp#test", function () { | ||
/o/.test("Hello World!"); | ||
}) | ||
.add("String#indexOf", function () { | ||
"Hello World!".indexOf("o") > -1; | ||
}) | ||
// add listeners | ||
.on("cycle", function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
// run async | ||
.run({ async: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "with-typescript", | ||
"private": true, | ||
"scripts": { | ||
"bench-benchmark-js": "node -r esbuild-register benchmark-js.ts", | ||
"bench-tinybench": "node -r esbuild-register tinybench.ts" | ||
}, | ||
"devDependencies": { | ||
"@codspeed/benchmark.js-plugin": "workspace:^1.1.0", | ||
"@codspeed/tinybench-plugin": "workspace:^1.1.0", | ||
"benchmark": "^2.1.4", | ||
"esbuild-register": "^3.4.2", | ||
"tinybench": "^2.5.0", | ||
"typescript": "^5.1.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { withCodSpeed } from "@codspeed/tinybench-plugin"; | ||
import { Bench } from "tinybench"; | ||
|
||
const bench = withCodSpeed(new Bench({ time: 100 })); | ||
|
||
bench | ||
.add("switch 1", () => { | ||
let a = 1; | ||
let b = 2; | ||
const c = a; | ||
a = b; | ||
b = c; | ||
}) | ||
.add("switch 2", () => { | ||
let a = 1; | ||
let b = 10; | ||
a = b + a; | ||
b = a - b; | ||
a = b - a; | ||
}); | ||
|
||
bench.run().then(() => { | ||
console.table( | ||
bench.tasks.map(({ name, result }) => ({ | ||
"Task Name": name, | ||
"Average Time (ps)": result?.mean ? result.mean * 1000 : "N/A", | ||
"Variance (ps)": result?.variance ? result.variance * 1000 : "N/A", | ||
})) | ||
); | ||
}); |
Oops, something went wrong.