-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add MaxBucketQueue add more benchmarks
- Loading branch information
Showing
21 changed files
with
769 additions
and
208 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,68 @@ | ||
import Benchmark from "benchmark"; | ||
import { MinBucketQueue } from "../src"; | ||
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(); | ||
|
||
const itemNumber = 1_000_000; | ||
const priorityMax = 1000; | ||
|
||
const items: number[] = []; | ||
|
||
for (let i = 0; i < itemNumber; i++) { | ||
items.push(i % priorityMax); | ||
} | ||
|
||
const bq = new MinBucketQueue<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], items[i]); | ||
heapjs.push(items[i]); | ||
heap.push(items[i]); | ||
heapds.push(items[i]); | ||
mpq.add(items[i]); | ||
pq.add(items[i]); | ||
} | ||
|
||
suit | ||
.add("MinBucketQueue", () => { | ||
for (let i = 0; i < 1000; i++) { | ||
bq.has(i); | ||
} | ||
}) | ||
.add("HeapJS", () => { | ||
for (let i = 0; i < 1000; i++) { | ||
heapjs.contains(i); | ||
} | ||
}) | ||
.add("Heap", () => { | ||
for (let i = 0; i < 1000; i++) { | ||
heap.contains(i); | ||
} | ||
}) | ||
.add("MinPriorityQueue", () => { | ||
for (let i = 0; i < 1000; i++) { | ||
mpq.has(i); | ||
} | ||
}) | ||
.add("PriorityQueue", () => { | ||
for (let i = 0; i < 1000; i++) { | ||
pq.has(i); | ||
} | ||
}) | ||
.on("cycle", function (e: Event) { | ||
console.log("" + e.target); | ||
}) | ||
.on("complete", function () { | ||
// @ts-expect-error - no error expected | ||
console.log("Fastest is " + this.filter("fastest").map("name")); | ||
}) | ||
.run(); |
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
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,75 @@ | ||
import Benchmark from "benchmark"; | ||
import { MinBucketQueue } from "../src"; | ||
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(); | ||
|
||
const itemNumber = 1_000_000; | ||
const priorityMax = 1000; | ||
|
||
const items: number[] = []; | ||
const itemsPrio: [number, number][] = []; | ||
|
||
for (let i = 0; i < itemNumber; i++) { | ||
items.push(i % priorityMax); | ||
itemsPrio.push([i % priorityMax, i % priorityMax]); | ||
} | ||
|
||
const bq = new MinBucketQueue<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], items[i]); | ||
heapjs.push(items[i]); | ||
heap.push(items[i]); | ||
heapds.push(items[i]); | ||
mpq.add(items[i]); | ||
pq.add(items[i]); | ||
} | ||
|
||
suit | ||
.add("MinBucketQueue", () => { | ||
bq.clear(); | ||
for (let i = 0; i < items.length; i++) { | ||
bq.push(items[i], items[i]); | ||
} | ||
}) | ||
.add("HeapJS", () => { | ||
heapjs.clear(); | ||
for (let i = 0; i < items.length; i++) { | ||
heapjs.push(items[i]); | ||
} | ||
}) | ||
.add("HeapDS", () => { | ||
heapds.clear(); | ||
for (let i = 0; i < items.length; i++) { | ||
heapds.push(items[i]); | ||
} | ||
}) | ||
.add("Heap", () => { | ||
heap.clear(); | ||
for (let i = 0; i < items.length; i++) { | ||
heap.push(items[i]); | ||
} | ||
}) | ||
.add("MinPriorityQueue", () => { | ||
mpq.refill(items); | ||
}) | ||
.add("PriorityQueue", () => { | ||
pq.refill(items); | ||
}) | ||
.on("cycle", function (e: Event) { | ||
console.log("" + e.target); | ||
}) | ||
.on("complete", function () { | ||
// @ts-expect-error - no error expected | ||
console.log("Fastest is " + this.filter("fastest").map("name")); | ||
}) | ||
.run(); |
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 |
---|---|---|
@@ -1,16 +1,32 @@ | ||
type Integer = number; | ||
type Priority = Integer; | ||
declare class BucketQueue<T> { | ||
private buckets; | ||
private priorityMax; | ||
private priorityMin; | ||
private _size; | ||
|
||
declare abstract class BucketQueue<T> { | ||
protected buckets: T[][]; | ||
protected pointer: number; | ||
protected _size: number; | ||
constructor(items?: [T, Priority][]); | ||
abstract push(item: T, priority: Priority): void; | ||
abstract pop(): T | undefined; | ||
add(item: T, priority: Priority): void; | ||
poll(): T | undefined; | ||
peek(): T | undefined; | ||
clear(): void; | ||
refill(items: [T, Priority][]): void; | ||
has(item: T): boolean; | ||
contains: (item: T) => boolean; | ||
toArray(): T[]; | ||
get size(): number; | ||
} | ||
|
||
declare class MaxBucketQueue<T> extends BucketQueue<T> { | ||
push(item: T, priority: Priority): void; | ||
pop(): T | undefined; | ||
} | ||
|
||
declare class MinBucketQueue<T> extends BucketQueue<T> { | ||
push(item: T, priority: Priority): void; | ||
private pop; | ||
popHighest(): T | undefined; | ||
popLowest(): T | undefined; | ||
get size(): Integer; | ||
pop(): T | undefined; | ||
} | ||
|
||
export { BucketQueue }; | ||
export { type Integer, MaxBucketQueue, MinBucketQueue, type Priority }; |
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 |
---|---|---|
@@ -1,16 +1,32 @@ | ||
type Integer = number; | ||
type Priority = Integer; | ||
declare class BucketQueue<T> { | ||
private buckets; | ||
private priorityMax; | ||
private priorityMin; | ||
private _size; | ||
|
||
declare abstract class BucketQueue<T> { | ||
protected buckets: T[][]; | ||
protected pointer: number; | ||
protected _size: number; | ||
constructor(items?: [T, Priority][]); | ||
abstract push(item: T, priority: Priority): void; | ||
abstract pop(): T | undefined; | ||
add(item: T, priority: Priority): void; | ||
poll(): T | undefined; | ||
peek(): T | undefined; | ||
clear(): void; | ||
refill(items: [T, Priority][]): void; | ||
has(item: T): boolean; | ||
contains: (item: T) => boolean; | ||
toArray(): T[]; | ||
get size(): number; | ||
} | ||
|
||
declare class MaxBucketQueue<T> extends BucketQueue<T> { | ||
push(item: T, priority: Priority): void; | ||
pop(): T | undefined; | ||
} | ||
|
||
declare class MinBucketQueue<T> extends BucketQueue<T> { | ||
push(item: T, priority: Priority): void; | ||
private pop; | ||
popHighest(): T | undefined; | ||
popLowest(): T | undefined; | ||
get size(): Integer; | ||
pop(): T | undefined; | ||
} | ||
|
||
export { BucketQueue }; | ||
export { type Integer, MaxBucketQueue, MinBucketQueue, type Priority }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.