-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
748da44
commit 2208353
Showing
2 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { benchmark } from "@thi.ng/bench"; | ||
import { SYSTEM } from "@thi.ng/random"; | ||
import { repeatedly } from "@thi.ng/transducers"; | ||
import { DHeap, Heap, PairingHeap } from "../src"; | ||
|
||
const generateValues = (num = 1e5) => [...repeatedly(() => SYSTEM.int(), num)]; | ||
|
||
const buildHeap = (vals: number[]) => new Heap(vals); | ||
|
||
const buildDHeap = (vals: number[], d = 4) => new DHeap(vals, { d }); | ||
|
||
const buildPHeap = (vals: number[]) => new PairingHeap(vals); | ||
|
||
const drainHeap = (vals: number[]) => { | ||
const h = buildHeap(vals); | ||
while (h.length) { | ||
h.pop(); | ||
} | ||
}; | ||
|
||
const drainDHeap = (vals: number[], d = 4) => { | ||
const h = buildDHeap(vals, d); | ||
while (h.length) { | ||
h.pop(); | ||
} | ||
}; | ||
|
||
const drainPHeap = (vals: number[]) => { | ||
const h = buildPHeap(vals); | ||
while (h.length) { | ||
h.pop(); | ||
} | ||
}; | ||
|
||
const vals = generateValues(1e3); | ||
|
||
let opts = { iter: 1000, warmup: 100 }; | ||
|
||
benchmark(() => buildHeap(vals), { ...opts, title: "build heap" }); | ||
benchmark(() => buildDHeap(vals), { ...opts, title: "build dheap(4)" }); | ||
benchmark(() => buildPHeap(vals), { ...opts, title: "build pheap" }); | ||
|
||
benchmark(() => drainHeap(vals), { ...opts, title: "drain heap" }); | ||
benchmark(() => drainDHeap(vals), { ...opts, title: "drain dheap(4)" }); | ||
benchmark(() => drainPHeap(vals), { ...opts, title: "drain pheap" }); |
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,10 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../build", | ||
"module": "commonjs", | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false | ||
}, | ||
"include": ["./**/*.ts", "../src/**/*.ts"] | ||
} |