[benchmark] generated a performance testing report.

This commit is contained in:
Revone 2023-11-02 09:24:06 +08:00
parent 68aa49f9b1
commit 9f2f0fca29
43 changed files with 260 additions and 35 deletions

1
.gitignore vendored
View file

@ -17,3 +17,4 @@ npm-debug.*
/umd
/docs
/coverage
/benchmark

View file

@ -5,5 +5,5 @@ module.exports = {
collectCoverage: true,
coverageReporters: ['clover', 'json', 'lcov', ['text', {skipFull: true}], "json-summary"],
coverageDirectory: 'coverage',
testPathIgnorePatterns: ['<rootDir>/test/integration/']
testPathIgnorePatterns: ['<rootDir>/test/integration/', '<rootDir>/test/performance/']
};

173
package-lock.json generated
View file

@ -15,22 +15,24 @@
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"auto-changelog": "^2.4.0",
"avl-tree-typed": "^1.41.1",
"avl-tree-typed": "^1.41.2",
"benchmark": "^2.1.4",
"binary-tree-typed": "^1.41.1",
"bst-typed": "^1.41.1",
"binary-tree-typed": "^1.41.2",
"bst-typed": "^1.41.2",
"dependency-cruiser": "^14.1.0",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"heap-typed": "^1.41.1",
"fast-glob": "^3.3.1",
"heap-typed": "^1.41.2",
"istanbul-badges-readme": "^1.8.5",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"tsup": "^7.2.0",
"typedoc": "^0.25.1",
"typescript": "^5.2.2"
@ -677,6 +679,28 @@
"integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==",
"dev": true
},
"node_modules/@cspotcode/source-map-support": {
"version": "0.8.1",
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
"integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==",
"dev": true,
"dependencies": {
"@jridgewell/trace-mapping": "0.3.9"
},
"engines": {
"node": ">=12"
}
},
"node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": {
"version": "0.3.9",
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz",
"integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==",
"dev": true,
"dependencies": {
"@jridgewell/resolve-uri": "^3.0.3",
"@jridgewell/sourcemap-codec": "^1.4.10"
}
},
"node_modules/@esbuild/android-arm": {
"version": "0.18.20",
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz",
@ -1889,6 +1913,30 @@
"@sinonjs/commons": "^3.0.0"
}
},
"node_modules/@tsconfig/node10": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
"integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==",
"dev": true
},
"node_modules/@tsconfig/node12": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz",
"integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==",
"dev": true
},
"node_modules/@tsconfig/node14": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz",
"integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==",
"dev": true
},
"node_modules/@tsconfig/node16": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz",
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
"dev": true
},
"node_modules/@types/babel__core": {
"version": "7.20.3",
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.3.tgz",
@ -2573,6 +2621,12 @@
"node": ">= 8"
}
},
"node_modules/arg": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
"dev": true
},
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
@ -2728,12 +2782,12 @@
}
},
"node_modules/avl-tree-typed": {
"version": "1.41.1",
"resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.41.1.tgz",
"integrity": "sha512-uDby1QfHHFdDBDHlAHy0yLbzyv5EaqkJh2K7SRABLtdH1vFwEnyrEDYuVbnzt3WQpng6EnJQ/JJbuQTUw1bXHQ==",
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.41.2.tgz",
"integrity": "sha512-J3g1PuuxJdun24hgOgSvFwbOu3xykqabTRGRd78IU9yZBBVNNVTZ+oJkNR5OYWG3bgPhcv5x8dHbWsHi3S5QGQ==",
"dev": true,
"dependencies": {
"data-structure-typed": "^1.41.1"
"data-structure-typed": "^1.41.2"
}
},
"node_modules/babel-jest": {
@ -2927,12 +2981,12 @@
}
},
"node_modules/binary-tree-typed": {
"version": "1.41.1",
"resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.41.1.tgz",
"integrity": "sha512-DF64S/WE8kls21iutKQJfJmIJ/C4s7mFg6yQ7KFM2FCyvsQ3sGVUnOmbu7JQF4lEdDcEgu6YueODVchhEjxdKw==",
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.41.2.tgz",
"integrity": "sha512-x0nOUvCEWNpJsQXqXbEoGuVFt2dFpL/vRi8xny/sqvqeygDv/Vsw4puoLBXFd+UfmZN3Q/KBULHoy6pKTaXBqw==",
"dev": true,
"dependencies": {
"data-structure-typed": "^1.41.1"
"data-structure-typed": "^1.41.2"
}
},
"node_modules/brace-expansion": {
@ -3011,12 +3065,12 @@
}
},
"node_modules/bst-typed": {
"version": "1.41.1",
"resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.41.1.tgz",
"integrity": "sha512-YfKna3z8aBhT0EiVZ26i3Ui9VIYg+J+oPYl1oTAK2n74GwDBwOXnP6HRibaB09nB/NuHt9cL6+IXyDc0P3V8vg==",
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.41.2.tgz",
"integrity": "sha512-94a99sgCzWYddsHTPQaB3LzQeEGbQWnte/Wg6EMccH6Dpt42FJMXMQMP6N+3Y373wSppI804kN58EKWemo+4xA==",
"dev": true,
"dependencies": {
"data-structure-typed": "^1.41.1"
"data-structure-typed": "^1.41.2"
}
},
"node_modules/buffer-from": {
@ -3398,6 +3452,12 @@
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"node_modules/create-require": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
"dev": true
},
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@ -3413,9 +3473,9 @@
}
},
"node_modules/data-structure-typed": {
"version": "1.41.1",
"resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.41.1.tgz",
"integrity": "sha512-Upx3HQc+bsa5YtWGmmeBEoVN3i1onF1GacKX0vvjNQiXZoR93WwnJBISTlM/GO5vRmkproZ6FXKJzyEjKRY8bQ==",
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.41.2.tgz",
"integrity": "sha512-NqySco4pSZWLD1Y277AxTU+lJgiVIlkGkFSLdMRyYGsWcMCYlqmu2pryzm4E2jgI6FFzIgVqA6FBSTQKmxNchw==",
"dev": true
},
"node_modules/debug": {
@ -3558,6 +3618,15 @@
"node": ">=8"
}
},
"node_modules/diff": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
"dev": true,
"engines": {
"node": ">=0.3.1"
}
},
"node_modules/diff-sequences": {
"version": "29.6.3",
"resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz",
@ -4771,12 +4840,12 @@
}
},
"node_modules/heap-typed": {
"version": "1.41.1",
"resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.41.1.tgz",
"integrity": "sha512-TadRqSZCJG/Q9nRI2eThwpQBjIPpbTjkmGaAWu4ud3tKKOAyqFF4+HCtXRQZB2LY5sWmlY1tS/pe7g7AOq/q/Q==",
"version": "1.41.2",
"resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.41.2.tgz",
"integrity": "sha512-fDLjM5HJOqGFS52LJYOh3t5dUebh1ZPdRW83gtgqx3xfV1lVfM0RRFLFMJZ3OAqDVwE3XxKlUirOIfIL/Xfe9Q==",
"dev": true,
"dependencies": {
"data-structure-typed": "^1.41.1"
"data-structure-typed": "^1.41.2"
}
},
"node_modules/html-escaper": {
@ -8519,6 +8588,49 @@
"node": ">= 8"
}
},
"node_modules/ts-node": {
"version": "10.9.1",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz",
"integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==",
"dev": true,
"dependencies": {
"@cspotcode/source-map-support": "^0.8.0",
"@tsconfig/node10": "^1.0.7",
"@tsconfig/node12": "^1.0.7",
"@tsconfig/node14": "^1.0.0",
"@tsconfig/node16": "^1.0.2",
"acorn": "^8.4.1",
"acorn-walk": "^8.1.1",
"arg": "^4.1.0",
"create-require": "^1.1.0",
"diff": "^4.0.1",
"make-error": "^1.1.1",
"v8-compile-cache-lib": "^3.0.1",
"yn": "3.1.1"
},
"bin": {
"ts-node": "dist/bin.js",
"ts-node-cwd": "dist/bin-cwd.js",
"ts-node-esm": "dist/bin-esm.js",
"ts-node-script": "dist/bin-script.js",
"ts-node-transpile-only": "dist/bin-transpile.js",
"ts-script": "dist/bin-script-deprecated.js"
},
"peerDependencies": {
"@swc/core": ">=1.2.50",
"@swc/wasm": ">=1.2.50",
"@types/node": "*",
"typescript": ">=2.7"
},
"peerDependenciesMeta": {
"@swc/core": {
"optional": true
},
"@swc/wasm": {
"optional": true
}
}
},
"node_modules/tsconfig-paths": {
"version": "3.14.2",
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz",
@ -8959,6 +9071,12 @@
"punycode": "^2.1.0"
}
},
"node_modules/v8-compile-cache-lib": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==",
"dev": true
},
"node_modules/v8-to-istanbul": {
"version": "9.1.3",
"resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.3.tgz",
@ -9320,6 +9438,15 @@
"node": ">=8"
}
},
"node_modules/yn": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
"integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/yocto-queue": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",

View file

@ -33,6 +33,7 @@
"install:all-subs": "npm i avl-tree-typed binary-tree-typed bst-typed deque-typed directed-graph-typed doubly-linked-list-typed graph-typed heap-typed linked-list-typed max-heap-typed max-priority-queue-typed min-heap-typed min-priority-queue-typed priority-queue-typed singly-linked-list-typed stack-typed tree-multiset-typed trie-typed undirected-graph-typed queue-typed --save-dev",
"test": "jest",
"test:integration": "npm run update:subs && jest --config jest.integration.config.js",
"benchmark": "ts-node test/performance/index.ts",
"check:deps": "dependency-cruiser src",
"changelog": "auto-changelog",
"coverage:badge": "istanbul-badges-readme",
@ -62,22 +63,24 @@
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"auto-changelog": "^2.4.0",
"avl-tree-typed": "^1.41.1",
"avl-tree-typed": "^1.41.2",
"benchmark": "^2.1.4",
"binary-tree-typed": "^1.41.1",
"bst-typed": "^1.41.1",
"binary-tree-typed": "^1.41.2",
"bst-typed": "^1.41.2",
"dependency-cruiser": "^14.1.0",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"heap-typed": "^1.41.1",
"fast-glob": "^3.3.1",
"heap-typed": "^1.41.2",
"istanbul-badges-readme": "^1.8.5",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"tsup": "^7.2.0",
"typedoc": "^0.25.1",
"typescript": "^5.2.2"

View file

@ -1,17 +1,24 @@
#!/bin/bash
# Prompt the user for directory, extension, search string, and replace string
read -p "Enter the directory path (e.g., ./test): " directory
read -p "Enter the file extension (e.g., .txt): " extension
read -p "Enter the search string: " search_string
read -p "Enter the replace string: " replace_string
# iterate the directory to rename and clear content of files
rename_and_clear_files() {
local directory="$1"
local extension="$2"
local new_prefix="$3"
local search_string="$3"
local replace_string="$4"
for file in "$directory"/*; do
if [ -d "$file" ]; then
rename_and_clear_files "$file" "$extension" "$new_prefix"
rename_and_clear_files "$file" "$extension" "$search_string" "$replace_string"
elif [ -f "$file" ] && [[ "$file" == *"$extension" ]]; then
filename=$(basename "$file" "$extension")
new_name="$directory/${filename}${new_prefix}${extension}"
new_name="${directory}/${filename//$search_string/$replace_string}${extension}"
mv "$file" "$new_name"
echo "Renamed $file to $new_name"
> "$new_name" # clear content of file
@ -19,11 +26,12 @@ rename_and_clear_files() {
done
}
# check if directory, extension and prefix were provided
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 <directory> <extension> <new_prefix>"
# check if all required values are provided
if [ -z "$directory" ] || [ -z "$extension" ] || [ -z "$search_string" ] || [ -z "$replace_string" ]; then
echo "Usage: $0"
echo "Please provide the required information."
exit 1
fi
# evoke the recursive function to rename and clear files
rename_and_clear_files "$1" "$2" "$3"
rename_and_clear_files "$directory" "$extension" "$search_string" "$replace_string"

View file

@ -0,0 +1,19 @@
import {Deque} from "../../../../src";
import * as Benchmark from 'benchmark';
export const suite = new Benchmark.Suite();
suite
.add('push', () => {
const deque = new Deque<number>();
for (let i = 0; i < 10; i++) {
deque.push(i);
}
})
.add('shift', () => {
const deque = new Deque<number>();
for (let i = 0; i < 10; i++) {
deque.push(i);
deque.shift();
}
})

View file

@ -0,0 +1,20 @@
import {Queue} from "../../../../src";
import * as Benchmark from 'benchmark';
export const suite = new Benchmark.Suite();
suite
.add('push', () => {
const queue = new Queue<number>();
for (let i = 0; i < 1000000; i++) {
queue.push(i);
}
})
// .add('shift', () => {
// const queue = new Queue<number>();
// for (let i = 0; i < 10000; i++) {
// queue.push(i);
// queue.shift();
// }
// })

47
test/performance/index.ts Normal file
View file

@ -0,0 +1,47 @@
import * as Benchmark from 'benchmark';
import * as path from 'path';
import * as fs from 'fs';
import * as fastGlob from 'fast-glob';
const reportDistPath = 'benchmark';
const testDir = path.join(__dirname, 'data-structures');
const testFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts'));
const report: {[key: string] : any} = {};
let i = 0;
testFiles.forEach((file: string) => {
i++;
console.log(`testing file ${file}`);
const testName = path.basename(file, '.test.ts');
const testFunction = require(file);
const {suite} = testFunction;
if (suite) {
suite.on('cycle', (event: any) => {
console.log(String(event.target));
});
suite.on('complete', function (this: Benchmark.Suite) {
console.log('Fastest is ' + this.filter('fastest').map('name'));
report[testName] = this.map((test: Benchmark) => ({
name: test.name,
periodMS: test.times.period * 1000,
hz: test.hz,
count: test.count,
mean: test.stats.mean,
deviation: test.stats.deviation,
}));
// report[testName] = this;
console.log('----i', i, testFiles.length)
if (testFiles.length === i) {
if (!fs.existsSync(reportDistPath)) fs.mkdirSync(reportDistPath, { recursive: true });
const filePath = path.join(reportDistPath, 'report.json');
fs.writeFileSync(filePath, JSON.stringify(report, null, 2));
console.log('Performance test report file generated')
}
})
.run({async: true});
}
});