Skip to content

Commit

Permalink
chore: add a benchmark to get a feel for how fast scope variables are…
Browse files Browse the repository at this point in the history
… resolved
  • Loading branch information
josdejong committed Feb 8, 2024
1 parent 9fe4ffe commit 7d2497c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ require('./roots')
require('./matrix_operations')
require('./prime')
require('./load')
require('./scope_variables.js')
22 changes: 22 additions & 0 deletions test/benchmark/scope_variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// test performance of resolving scope variables in the expression parser

const Benchmark = require('benchmark')
const math = require('../..')

const scope = { a: 2, b: 3, c: 4 }
const f = math.evaluate('f(x, y) = a + b + c + x + y', scope)

console.log('f(5, 6) = ' + f(5, 6))

const results = []

const suite = new Benchmark.Suite()
let res = 0
suite
.add('evaluate f(x, y)', function () {
res = f(-res, res) // just make it dynamic, using res as argument
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run()

0 comments on commit 7d2497c

Please sign in to comment.