Skip to content

Commit

Permalink
Bench updates (#15029)
Browse files Browse the repository at this point in the history
Co-authored-by: RiskyMH <[email protected]>
  • Loading branch information
RiskyMH and RiskyMH authored Nov 9, 2024
1 parent 6357899 commit b541371
Show file tree
Hide file tree
Showing 128 changed files with 196 additions and 173 deletions.
20 changes: 20 additions & 0 deletions .buildkite/scripts/upload-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,25 @@ function upload_s3_file() {
run_command aws --endpoint-url="$AWS_ENDPOINT" s3 cp "$file" "s3://$AWS_BUCKET/$folder/$file"
}

function send_bench_webhook() {
if [ -z "$BENCHMARK_URL" ]; then
return 1
fi

local tag="$1"
local commit="$BUILDKITE_COMMIT"
local artifact_path="${commit}"

if [ "$tag" == "canary" ]; then
artifact_path="${commit}-canary"
fi

local artifact_url="https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/$artifact_path/bun-linux-x64.zip"
local webhook_url="$BENCHMARK_URL?tag=$tag&commit=$commit&artifact_url=$artifact_url"

curl -X POST "$webhook_url"
}

function create_release() {
assert_main
assert_buildkite_agent
Expand Down Expand Up @@ -206,6 +225,7 @@ function create_release() {

update_github_release "$tag"
create_sentry_release "$tag"
send_bench_webhook "$tag"
}

function assert_canary() {
Expand Down
2 changes: 1 addition & 1 deletion bench/async/bun.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

bench("sync", () => {});
bench("async", async () => {});
Expand Down
2 changes: 1 addition & 1 deletion bench/async/deno.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "../node_modules/mitata/src/cli.mjs";
import { bench, run } from "../runner.mjs";

bench("sync", () => {});
bench("async", async () => {});
Expand Down
2 changes: 1 addition & 1 deletion bench/async/node.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

bench("sync", () => {});
bench("async", async () => {});
Expand Down
Binary file modified bench/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion bench/copyfile/node.mitata.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bench, run } from "mitata";
import { copyFileSync, statSync, writeFileSync } from "node:fs";
import { bench, run } from "../runner.mjs";

function runner(ready) {
for (let size of [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000]) {
Expand Down
2 changes: 1 addition & 1 deletion bench/crypto/asymmetricCipher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";
const crypto = require("node:crypto");

const keyPair = crypto.generateKeyPairSync("rsa", {
Expand Down
2 changes: 1 addition & 1 deletion bench/crypto/asymmetricSign.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";
const crypto = require("node:crypto");

const keyPair = crypto.generateKeyPairSync("rsa", {
Expand Down
2 changes: 1 addition & 1 deletion bench/deepEqual/map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "bun:test";
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

const MAP_SIZE = 10_000;

Expand Down
2 changes: 1 addition & 1 deletion bench/deepEqual/set.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "bun:test";
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

const SET_SIZE = 10_000;

Expand Down
2 changes: 1 addition & 1 deletion bench/emitter/implementations.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { group } from "mitata";
import EventEmitterNative from "node:events";
import { group } from "../runner.mjs";

export const implementations = [
{
Expand Down
2 changes: 1 addition & 1 deletion bench/emitter/microbench.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";
import { groupForEmitter } from "./implementations.mjs";

var id = 0;
Expand Down
2 changes: 1 addition & 1 deletion bench/emitter/microbench_once.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";
import { groupForEmitter } from "./implementations.mjs";

var id = 0;
Expand Down
2 changes: 1 addition & 1 deletion bench/emitter/realworld_stream.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";
import { groupForEmitter } from "./implementations.mjs";

// Pseudo RNG is derived from https://stackoverflow.com/a/424445
Expand Down
2 changes: 1 addition & 1 deletion bench/fetch/bun.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

const count = 100;

Expand Down
2 changes: 1 addition & 1 deletion bench/fetch/node.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

const count = 100;

Expand Down
2 changes: 1 addition & 1 deletion bench/ffi/bun.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CString, dlopen, ptr } from "bun:ffi";
import { bench, group, run } from "mitata";
import { bench, group, run } from "../runner.mjs";

const { napiNoop, napiHash, napiString } = require(import.meta.dir + "/src/ffi_napi_bench.node");

Expand Down
2 changes: 1 addition & 1 deletion bench/ffi/deno.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, group, run } from "../node_modules/mitata/src/cli.mjs";
import { bench, group, run } from "../runner.mjs";

const extension = "darwin" !== Deno.build.os ? "so" : "dylib";
const path = new URL("src/target/release/libffi_napi_bench." + extension, import.meta.url).pathname;
Expand Down
2 changes: 1 addition & 1 deletion bench/ffi/node.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bench, group, run } from "mitata";
import { createRequire } from "node:module";
import { bench, group, run } from "../runner.mjs";

const require = createRequire(import.meta.url);
const { napiNoop, napiHash, napiString } = require("./src/ffi_napi_bench.node");
Expand Down
9 changes: 5 additions & 4 deletions bench/glob/braces.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import braces from "braces";
import { bench, group, run } from "mitata";
import { bench, group, run } from "../runner.mjs";

// const iterations = 1000;
const iterations = 100;
Expand All @@ -10,15 +10,16 @@ const veryComplexPattern = "{a,b,HI{c,e,LMAO{d,f}Q}}{1,2,{3,4},5}";

console.log(braces(complexPattern, { expand: true }));
function benchPattern(pattern, name) {
group({ name: `${name} pattern: "${pattern}"`, summary: true }, () => {
const _name = `${name} pattern: "${pattern}"`;
group({ name: _name, summary: true }, () => {
if (typeof Bun !== "undefined")
bench("Bun", () => {
bench(`Bun (${_name})`, () => {
for (let i = 0; i < iterations; i++) {
Bun.$.braces(pattern);
}
});

bench("micromatch/braces", () => {
bench(`micromatch/braces ${_name}`, () => {
for (let i = 0; i < iterations; i++) {
braces(pattern, { expand: true });
}
Expand Down
2 changes: 1 addition & 1 deletion bench/glob/match.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import micromatch from "micromatch";
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

const Glob = typeof Bun !== "undefined" ? Bun.Glob : undefined;
const doMatch = typeof Bun === "undefined" ? micromatch.isMatch : (a, b) => new Glob(b).match(a);
Expand Down
2 changes: 1 addition & 1 deletion bench/glob/scan.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fg from "fast-glob";
import { fdir } from "fdir";
import { bench, group, run } from "mitata";
import { bench, group, run } from "../runner.mjs";

const normalPattern = "*.ts";
const recursivePattern = "**/*.ts";
Expand Down
2 changes: 1 addition & 1 deletion bench/gzip/bun.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gunzipSync, gzipSync } from "bun";
import { bench, group, run } from "mitata";
import { bench, group, run } from "../runner.mjs";

const data = await Bun.file(require.resolve("@babel/standalone/babel.min.js")).arrayBuffer();

Expand Down
2 changes: 1 addition & 1 deletion bench/gzip/deno.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "../node_modules/mitata/src/cli.mjs";
import { bench, run } from "../runner.mjs";

const data = new TextEncoder().encode("Hello World!".repeat(9999));

Expand Down
2 changes: 1 addition & 1 deletion bench/gzip/node.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from "fs";
import { bench, run } from "mitata";
import { createRequire } from "module";
import { gunzipSync, gzipSync } from "zlib";
import { bench, run } from "../runner.mjs";

const require = createRequire(import.meta.url);
const data = readFileSync(require.resolve("@babel/standalone/babel.min.js"));
Expand Down
2 changes: 1 addition & 1 deletion bench/log/bun.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

bench("console.log('hello')", () => console.log("hello"));
bench("console.log({ hello: 'object' })", () => console.log({ hello: "object" }));
Expand Down
2 changes: 1 addition & 1 deletion bench/log/deno.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "../node_modules/mitata/src/cli.mjs";
import { bench, run } from "../runner.mjs";

bench("console.log", () => console.log("hello"));
bench("console.log({ hello: 'object' })", () => console.log({ hello: "object" }));
Expand Down
2 changes: 1 addition & 1 deletion bench/log/node.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

bench("console.log", () => console.log("hello"));
bench("console.log({ hello: 'object' })", () => console.log({ hello: "object" }));
Expand Down
2 changes: 1 addition & 1 deletion bench/modules/node_os/bun.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../../runner.mjs";
import {
arch,
cpus,
Expand Down
2 changes: 1 addition & 1 deletion bench/modules/node_os/node.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { bench, run } from "mitata";
import {
arch,
cpus,
Expand All @@ -19,6 +18,7 @@ import {
userInfo,
version,
} from "node:os";
import { bench, run } from "../../runner.mjs";

bench("cpus()", () => cpus());
bench("networkInterfaces()", () => networkInterfaces());
Expand Down
4 changes: 3 additions & 1 deletion bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"execa": "^8.0.1",
"fast-glob": "3.3.1",
"fdir": "^6.1.0",
"mitata": "^0.1.6",
"mitata": "^1.0.10",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"string-width": "7.1.0",
"tinycolor2": "^1.6.0",
"zx": "^7.2.3"
Expand Down
19 changes: 19 additions & 0 deletions bench/runner.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Mitata from "mitata";
import process from "node:process";

const asJSON = !!process?.env?.BENCHMARK_RUNNER;

/** @param {Parameters<typeof Mitata["run"]>["0"]} opts */
export function run(opts = {}) {
if (asJSON) {
opts.format = "json";
}

return Mitata.run(opts);
}

export const bench = Mitata.bench;

export function group(_name, fn) {
return Mitata.group(fn);
}
2 changes: 1 addition & 1 deletion bench/snippets/array-arguments-slice.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

function doIt(...args) {
// we use .at() to prevent constant folding optimizations
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/array-map.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://github.com/oven-sh/bun/issues/1096
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

const identity = x => x;

Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/array-shift.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

var myArray = new Array(5);
bench("[1, 2, 3, 4, 5].shift()", () => {
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/array-sort.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";
var comparator = (a, b) => a - b;

const numbers = [
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/arraybuffersink.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @runtime bun
import { ArrayBufferSink } from "bun";
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

var short = "Hello World!";
var shortUTF16 = "Hello World 💕💕💕";
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/assert.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from "assert";
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

bench("deepEqual", () => {
assert.deepEqual({ foo: "123", bar: "baz" }, { foo: "123", bar: "baz" });
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/async-overhead.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "mitata";
import { bench, run } from "../runner.mjs";

bench("noop", function () {});
bench("async function(){}", async function () {});
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/atob.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

function makeBenchmark(size) {
const latin1 = btoa("A".repeat(size));
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/blob.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "../node_modules/mitata/src/cli.mjs";
import { bench, run } from "../runner.mjs";

bench("new Blob(['hello world'])", function () {
return new Blob(["hello world"]);
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/buffer-base64.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

function makeBenchmark(size, isToString) {
const base64Input = Buffer.alloc(size, "latin1").toString("base64");
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/buffer-concat.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

for (let size of [32, 2048, 1024 * 16, 1024 * 1024 * 2, 1024 * 1024 * 16]) {
const first = Buffer.allocUnsafe(size);
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/buffer-create.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @runtime bun,node,deno
import { Buffer } from "node:buffer";
import process from "node:process";
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

const N = parseInt(process.env.RUN_COUNTER ?? "10000", 10);
var isBuffer = new Buffer(0);
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/buffer-fill.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

for (let size of [32, 2048, 1024 * 16, 1024 * 1024 * 2, 1024 * 1024 * 16]) {
for (let fillSize of [4, 8, 16, 11]) {
Expand Down
2 changes: 1 addition & 1 deletion bench/snippets/buffer-to-string.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Buffer } from "node:buffer";
import crypto from "node:crypto";
import { bench, run } from "./runner.mjs";
import { bench, run } from "../runner.mjs";

const bigBuffer = Buffer.from("hello world".repeat(10000));
const converted = bigBuffer.toString("base64");
Expand Down
8 changes: 4 additions & 4 deletions bench/snippets/color.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Color from "color";
import tinycolor from "tinycolor2";
import { bench, group, run } from "./runner.mjs";
import { bench, group, run } from "../runner.mjs";

const inputs = ["#f00", "rgb(255, 0, 0)", "rgba(255, 0, 0, 1)", "hsl(0, 100%, 50%)"];

for (const input of inputs) {
group(`${input}`, () => {
if (typeof Bun !== "undefined") {
bench("Bun.color()", () => {
bench(`Bun.color() (${input})`, () => {
Bun.color(input, "css");
});
}

bench("color", () => {
bench(`color (${input})`, () => {
Color(input).hex();
});

bench("'tinycolor2'", () => {
bench(`'tinycolor2' (${input})`, () => {
tinycolor(input).toHexString();
});
});
Expand Down
Loading

0 comments on commit b541371

Please sign in to comment.