Skip to content

Commit

Permalink
add more benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
keriati committed Jan 2, 2024
1 parent 4e8f97d commit daf178f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 23 deletions.
87 changes: 66 additions & 21 deletions benchmark/popPush.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,92 @@
import Benchmark from "benchmark";
import { BucketQueue } from "../src";
import Heap from "heap-js";
import HeapJS from "heap-js";
import Heap from "heap";
import { MinHeap as HeapDS } from "@datastructures-js/heap";
import { PriorityQueue, MinPriorityQueue } from "priority-queue-typed";

const suit = new Benchmark.Suite({
initCount: 1000,
});
const suit = new Benchmark.Suite();

const rounds = 1_000_000;
const priorityMax = 1_000;
const itemNumber = 10_000_000;
const priorityMax = 1000;

const items: [string, number][] = [];
const items: number[] = [];

for (let i = 0; i < rounds; i++) {
items.push([`item-${i}`, i % priorityMax]);
for (let i = 0; i < itemNumber; i++) {
items.push(i % priorityMax);
}

const bq = new BucketQueue<string>();
const heap = new Heap<[string, number]>((a, b) => a[1] - b[1]);
const bq = new BucketQueue<number>();
const heapjs = new HeapJS<number>((a, b) => a - b);
const heap = new Heap<number>((a, b) => a - b);
const heapds = new HeapDS<number>();
const mpq = new MinPriorityQueue<number>();
const pq = new PriorityQueue<number>([], { comparator: (a, b) => a - b });

for (let i = 0; i < items.length; i++) {
bq.push(items[i][0], items[i][1]);
bq.push(items[i], items[i]);
heapjs.push(items[i]);
heap.push(items[i]);
heapds.push(items[i]);
mpq.add(items[i]);
pq.add(items[i]);
}

suit
.add("BucketQueue", () => {
const i1 = bq.popLowest() as string;
const i2 = bq.popLowest() as string;
const i3 = bq.popLowest() as string;
const i1 = bq.popLowest() as number;
const i2 = bq.popLowest() as number;
const i3 = bq.popLowest() as number;

bq.push(i3, 0);
bq.push(i2, 0);
bq.push(i1, 0);
bq.push(i3, i3);
bq.push(i2, i2);
bq.push(i1, i1);
})
.add("HeapJS", () => {
const i1 = heapjs.pop() as number;
const i2 = heapjs.pop() as number;
const i3 = heapjs.pop() as number;

heapjs.push(i3);
heapjs.push(i2);
heapjs.push(i1);
})
.add("HeapDS", () => {
const i1 = heapds.pop() as number;
const i2 = heapds.pop() as number;
const i3 = heapds.pop() as number;

heapds.push(i3);
heapds.push(i2);
heapds.push(i1);
})
.add("Heap", () => {
const i1 = heap.pop() as [string, number];
const i2 = heap.pop() as [string, number];
const i3 = heap.pop() as [string, number];
const i1 = heap.pop() as number;
const i2 = heap.pop() as number;
const i3 = heap.pop() as number;

heap.push(i3);
heap.push(i2);
heap.push(i1);
})
.add("MinPriorityQueue", () => {
const i1 = mpq.poll() as number;
const i2 = mpq.poll() as number;
const i3 = mpq.poll() as number;

mpq.add(i3);
mpq.add(i2);
mpq.add(i1);
})
.add("PriorityQueue", () => {
const i1 = pq.poll() as number;
const i2 = pq.poll() as number;
const i3 = pq.poll() as number;

pq.add(i3);
pq.add(i2);
pq.add(i1);
})
.on("cycle", function (e: Event) {
console.log("" + e.target);
})
Expand Down
41 changes: 39 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@
"homepage": "https://github.com/keriati/bucket-priority-queue",
"license": "MIT",
"devDependencies": {
"@datastructures-js/heap": "^4.3.2",
"@types/benchmark": "^2.1.5",
"@types/heap": "^0.2.34",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"benchmark": "^2.1.4",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"heap": "^0.2.7",
"heap-js": "^2.3.0",
"jest": "^29.7.0",
"prettier": "^3.1.1",
"priority-queue-typed": "^1.50.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
Expand Down

0 comments on commit daf178f

Please sign in to comment.