feat: The performance report generator supports parameter filtering commands, which can be used to run specific tests individually. It generates individual performance comparison reports. Enrich the COMMANDS.md document.

This commit is contained in:
Revone 2023-11-16 21:08:57 +08:00
parent f9b6f313c6
commit 2b7bf3ce95
2 changed files with 114 additions and 114 deletions

View file

@ -786,115 +786,115 @@ export class FibonacciHeap<E> {
}
export class CHeap<T> {
protected _length = 0;
private readonly _priorityQueue: T[] = [];
private readonly _cmp: (x: T, y: T) => number;
constructor(
cmp: (x: T, y: T) => number =
function (x: T, y: T) {
if (x > y) return -1;
if (x < y) return 1;
return 0;
},
copy = true
) {
this._cmp = cmp;
}
clear() {
this._length = 0;
this._priorityQueue.length = 0;
}
push(item: T) {
this._priorityQueue.push(item);
this._pushUp(this._length);
this._length += 1;
}
pop() {
if (this._length === 0) return;
const value = this._priorityQueue[0];
const last = this._priorityQueue.pop()!;
this._length -= 1;
if (this._length) {
this._priorityQueue[0] = last;
this._pushDown(0, this._length >> 1);
}
return value;
}
top(): T | undefined {
return this._priorityQueue[0];
}
find(item: T) {
return this._priorityQueue.indexOf(item) >= 0;
}
remove(item: T) {
const index = this._priorityQueue.indexOf(item);
if (index < 0) return false;
if (index === 0) {
this.pop();
} else if (index === this._length - 1) {
this._priorityQueue.pop();
this._length -= 1;
} else {
this._priorityQueue.splice(index, 1, this._priorityQueue.pop()!);
this._length -= 1;
this._pushUp(index);
this._pushDown(index, this._length >> 1);
}
return true;
}
updateItem(item: T) {
const index = this._priorityQueue.indexOf(item);
if (index < 0) return false;
this._pushUp(index);
this._pushDown(index, this._length >> 1);
return true;
}
toArray() {
return [...this._priorityQueue];
}
private _pushUp(pos: number) {
const item = this._priorityQueue[pos];
while (pos > 0) {
const parent = (pos - 1) >> 1;
const parentItem = this._priorityQueue[parent];
if (this._cmp(parentItem, item) <= 0) break;
this._priorityQueue[pos] = parentItem;
pos = parent;
}
this._priorityQueue[pos] = item;
}
private _pushDown(pos: number, halfLength: number) {
const item = this._priorityQueue[pos];
while (pos < halfLength) {
let left = pos << 1 | 1;
const right = left + 1;
let minItem = this._priorityQueue[left];
if (
right < this._length &&
this._cmp(minItem, this._priorityQueue[right]) > 0
) {
left = right;
minItem = this._priorityQueue[right];
}
if (this._cmp(minItem, item) >= 0) break;
this._priorityQueue[pos] = minItem;
pos = left;
}
this._priorityQueue[pos] = item;
}
}
// export class CHeap<T> {
//
// protected _length = 0;
// private readonly _priorityQueue: T[] = [];
// private readonly _cmp: (x: T, y: T) => number;
//
// constructor(
// cmp: (x: T, y: T) => number =
// function (x: T, y: T) {
// if (x > y) return -1;
// if (x < y) return 1;
// return 0;
// },
// copy = true
// ) {
//
// this._cmp = cmp;
//
// }
//
// clear() {
// this._length = 0;
// this._priorityQueue.length = 0;
// }
//
// push(item: T) {
// this._priorityQueue.push(item);
// this._pushUp(this._length);
// this._length += 1;
// }
//
// pop() {
// if (this._length === 0) return;
// const value = this._priorityQueue[0];
// const last = this._priorityQueue.pop()!;
// this._length -= 1;
// if (this._length) {
// this._priorityQueue[0] = last;
// this._pushDown(0, this._length >> 1);
// }
// return value;
// }
//
// top(): T | undefined {
// return this._priorityQueue[0];
// }
//
// find(item: T) {
// return this._priorityQueue.indexOf(item) >= 0;
// }
//
// remove(item: T) {
// const index = this._priorityQueue.indexOf(item);
// if (index < 0) return false;
// if (index === 0) {
// this.pop();
// } else if (index === this._length - 1) {
// this._priorityQueue.pop();
// this._length -= 1;
// } else {
// this._priorityQueue.splice(index, 1, this._priorityQueue.pop()!);
// this._length -= 1;
// this._pushUp(index);
// this._pushDown(index, this._length >> 1);
// }
// return true;
// }
//
// updateItem(item: T) {
// const index = this._priorityQueue.indexOf(item);
// if (index < 0) return false;
// this._pushUp(index);
// this._pushDown(index, this._length >> 1);
// return true;
// }
//
// toArray() {
// return [...this._priorityQueue];
// }
//
// private _pushUp(pos: number) {
// const item = this._priorityQueue[pos];
// while (pos > 0) {
// const parent = (pos - 1) >> 1;
// const parentItem = this._priorityQueue[parent];
// if (this._cmp(parentItem, item) <= 0) break;
// this._priorityQueue[pos] = parentItem;
// pos = parent;
// }
// this._priorityQueue[pos] = item;
// }
//
// private _pushDown(pos: number, halfLength: number) {
// const item = this._priorityQueue[pos];
// while (pos < halfLength) {
// let left = pos << 1 | 1;
// const right = left + 1;
// let minItem = this._priorityQueue[left];
// if (
// right < this._length &&
// this._cmp(minItem, this._priorityQueue[right]) > 0
// ) {
// left = right;
// minItem = this._priorityQueue[right];
// }
// if (this._cmp(minItem, item) >= 0) break;
// this._priorityQueue[pos] = minItem;
// pos = left;
// }
// this._priorityQueue[pos] = item;
// }
// }

View file

@ -1,5 +1,5 @@
import { CHeap, FibonacciHeap, MaxHeap, MinHeap } from '../../../../src';
import { calcRunTime, logBigOMetricsWrap } from '../../../utils';
import { FibonacciHeap, MaxHeap, MinHeap } from '../../../../src';
import { logBigOMetricsWrap } from '../../../utils';
describe('Heap Operation Test', () => {
it('should numeric heap work well', function () {