Compare commits

..

1 Commits

Author SHA1 Message Date
f1a2d04f4b feat: working benchmark of pocomath 2023-08-15 17:38:31 -07:00
3 changed files with 76 additions and 0 deletions

43
benchmark/roots.mjs Normal file
View File

@ -0,0 +1,43 @@
import Benchmark from 'benchmark'
import padRight from 'pad-right'
import math from '../src/pocomath.mjs'
function pad (text) {
return padRight(text, 40, ' ')
}
const maxCoeff = 5
function countRoots () {
let polys = 0
let roots = 0
for (let d = 0; d <= maxCoeff; ++d) {
for (let c = 0; c <= maxCoeff; ++c) {
for (let b = 0; b <= maxCoeff; ++b) {
for (let a = 1; a <= maxCoeff; ++a) {
polys += 1
roots += math.length(math.polynomialRoot(d, c, b, a))
}
}
}
}
return [polys, roots]
}
const test = countRoots()
console.log('There are', test[1], 'roots of the', test[0], 'integer cubic')
console.log('polynomials (with coefficients <=', maxCoeff, ')')
const results = []
const suite = new Benchmark.Suite()
suite
.add(pad('count roots'), function () {
const res = countRoots()
results.push(res)
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.on('complete', function () {
})
.run()

View File

@ -20,7 +20,9 @@
license: 'Apache-2.0',
type: 'module',
devDependencies: {
benchmark: '^2.1.4',
mocha: '^10.0.0',
'pad-right': '^0.2.2',
},
dependencies: {
'bigint-isqrt': '^0.2.1',

View File

@ -1,9 +1,11 @@
lockfileVersion: 5.4
specifiers:
benchmark: ^2.1.4
bigint-isqrt: ^0.2.1
fraction.js: ^4.2.0
mocha: ^10.0.0
pad-right: ^0.2.2
typed-function: ^3.0.0
dependencies:
@ -12,7 +14,9 @@ dependencies:
typed-function: 3.0.0
devDependencies:
benchmark: 2.1.4
mocha: 10.0.0
pad-right: 0.2.2
packages:
@ -53,6 +57,13 @@ packages:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
dev: true
/benchmark/2.1.4:
resolution: {integrity: sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ==}
dependencies:
lodash: 4.17.21
platform: 1.3.6
dev: true
/bigint-isqrt/0.2.1:
resolution: {integrity: sha512-x43s2Qx5l5ShFZFA5xejJfPtV1vXISyWUXlrZeJTx9F6D2ex3BR6AwWnIz4ITAu5nTy3hp+d+ClGu7qUGcgY8g==}
dev: false
@ -307,6 +318,10 @@ packages:
p-locate: 5.0.0
dev: true
/lodash/4.17.21:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
dev: true
/log-symbols/4.1.0:
resolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==}
engines: {node: '>=10'}
@ -396,6 +411,13 @@ packages:
p-limit: 3.1.0
dev: true
/pad-right/0.2.2:
resolution: {integrity: sha512-4cy8M95ioIGolCoMmm2cMntGR1lPLEbOMzOKu8bzjuJP6JpzEMQcDHmh7hHLYGgob+nKe1YHFMaG4V59HQa89g==}
engines: {node: '>=0.10.0'}
dependencies:
repeat-string: 1.6.1
dev: true
/path-exists/4.0.0:
resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==}
engines: {node: '>=8'}
@ -411,6 +433,10 @@ packages:
engines: {node: '>=8.6'}
dev: true
/platform/1.3.6:
resolution: {integrity: sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==}
dev: true
/randombytes/2.1.0:
resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==}
dependencies:
@ -424,6 +450,11 @@ packages:
picomatch: 2.3.1
dev: true
/repeat-string/1.6.1:
resolution: {integrity: sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==}
engines: {node: '>=0.10'}
dev: true
/require-directory/2.1.1:
resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==}
engines: {node: '>=0.10.0'}