diff --git a/scripts/benchmark.js b/scripts/benchmark.js new file mode 100644 index 0000000..d495226 --- /dev/null +++ b/scripts/benchmark.js @@ -0,0 +1,39 @@ + + + +let { Matrix, SVD, LU, EVD } = require('../matrix'); + +const algorithms = [SVD, LU, EVD]; + +const benchmarks = []; + +test(10); +test(100); +test(500); +test(1000); +test(1500); + +console.table(benchmarks); + +function test(size) { + const benchmark = {}; + benchmark.size = size; + benchmarks.push(benchmark); + + for (const Algo of algorithms) { + const matrix = Matrix.rand(size, size); + let count = 1; + const start = performance.now(); + const results = [new Algo(matrix)]; + const current = performance.now() - start; + if (current < 5000) { + count = Math.ceil(5000 / current); + for (let i = 0; i < count - 1; i++) { + results.push(new Algo(matrix)); + } + } + const time = (performance.now() - start) / results.length; + benchmark[Algo.name] = time; + console.log(`${Algo.name} ${size}x${size} matrix: ${time}ms (${count}x)`) + } +} \ No newline at end of file diff --git a/src/matrix.js b/src/matrix.js index c98253b..2844007 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -1579,11 +1579,13 @@ export default class Matrix extends AbstractMatrix { set(rowIndex, columnIndex, value) { this.data[rowIndex][columnIndex] = value; + //this.data[columnIndex][rowIndex] = value; return this; } get(rowIndex, columnIndex) { return this.data[rowIndex][columnIndex]; + //return this.data[columnIndex][rowIndex]; } removeRow(index) {