Skip to content

Commit

Permalink
Update the benchmark to reflect the changes in export
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Dec 11, 2024
1 parent 1f1c661 commit d88b852
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions test/perf/iteration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from "node:assert";
import {itBench, describe, it, setBenchOpts} from "../../src/index.js";
import {bench, describe, setBenchOpts} from "../../src/index.js";

// As of Jun 17 2021
// Compare state root
Expand All @@ -11,23 +10,19 @@ import {itBench, describe, it, setBenchOpts} from "../../src/index.js";
describe("Array iteration", () => {
setBenchOpts({maxMs: 60 * 1000, convergeFactor: 0.1 / 100});

it("Regular test", () => {
assert.strictEqual(1 + 2, 3);
});

// nonce = 5
const n = 1e6;
const arr = Array.from({length: n}, (_, i) => i);

itBench("sum array with raw for loop", () => {
bench("sum array with raw for loop", () => {
let sum = 0;
for (let i = 0, len = arr.length; i < len; i++) {
sum += i;
}
return sum;
});

itBench("sum array with reduce", () => {
bench("sum array with reduce", () => {
arr.reduce((total, curr) => total + curr, 0);

// Uncomment below to cause a guaranteed performance regression
Expand All @@ -37,7 +32,7 @@ describe("Array iteration", () => {

// Test before and beforeEach hooks

itBench({
bench({
id: "sum array with reduce beforeEach",
beforeEach: () => Array.from({length: 1e4}, (_, i) => i),
fn: () => {
Expand All @@ -49,7 +44,7 @@ describe("Array iteration", () => {
},
});

itBench({
bench({
id: "sum array with reduce before beforeEach",
before: () => Array.from({length: 1e4}, (_, i) => i),
beforeEach: (arr) => arr.slice(0),
Expand All @@ -62,25 +57,25 @@ describe("Array iteration", () => {
},
});

itBench.skip("sum array with reduce", () => {
bench.skip("sum array with reduce", () => {
arr.reduce((total, curr) => total + curr, 0);
});

// itBench.only("sum array with reduce", () => {
// bench.only("sum array with reduce", () => {
// arr.reduce((total, curr) => total + curr, 0);
// });

// Reporter options

itBench({
bench({
id: "sum array with reduce high threshold",
threshold: 5,
fn: () => {
arr.reduce((total, curr) => total + curr, 0);
},
});

itBench({
bench({
id: "sum array with reduce no threshold",
threshold: Infinity,
fn: () => {
Expand Down

0 comments on commit d88b852

Please sign in to comment.