Skip to content

Commit d67b73d

Browse files
committed
Added benchmarks
1 parent cdceb79 commit d67b73d

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/type/matrix/utils/matAlgo14xDs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ export const createMatAlgo14xDs = /* #__PURE__ */ factory(name, dependencies, ({
3434
cf = typed.find(callback, [adt, adt])
3535
}
3636

37-
return inverse ? a.map(v => cf(b, v)) : a.map(v => cf(v, b))
37+
return inverse ? a.map(v => cf(b, v), false, true) : a.map(v => cf(v, b), false, true)
3838
}
3939
})

src/type/matrix/utils/matAlgo15xAs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ export const createMatAlgo15xAs = /* #__PURE__ */ factory(name, dependencies, ()
2121
* https://github.com/josdejong/mathjs/pull/346#issuecomment-97659042
2222
*/
2323
return function matAlgo15xAs (a, b, cf, inverse) {
24-
return inverse ? map(a, v => cf(b, v)) : map(a, v => cf(v, b))
24+
return inverse ? map(a, v => cf(b, v), true) : map(a, v => cf(v, b), true)
2525
}
2626
})

test/benchmark/broadcast.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Bench } from 'tinybench'
2+
import { matrix, add, subtract, random } from '../../lib/esm/index.js'
3+
import { formatTaskResult } from './utils/formatTaskResult.js'
4+
5+
const array = random([500, 500], -10, 10)
6+
const genericMatrix = matrix(array)
7+
const numberMatrix = matrix(array, 'dense', 'number')
8+
9+
// console.log('data', array)
10+
// console.log('abs(data)', abs(array))npm run
11+
12+
const bench = new Bench({ time: 100, iterations: 100 })
13+
.add('add(array, 1)', () => {
14+
add(array, 1)
15+
})
16+
.add('add(matrix, 1)', () => {
17+
add(genericMatrix, 1)
18+
})
19+
.add('add(numberMatrix, 1)', () => {
20+
add(numberMatrix, 1)
21+
})
22+
.add('subtract(array, 1)', () => {
23+
subtract(array, 1)
24+
})
25+
.add('subtract(matrix, 1)', () => {
26+
subtract(genericMatrix, 1)
27+
})
28+
.add('subtract(numberMatrix, 1)', () => {
29+
subtract(numberMatrix, 1)
30+
})
31+
32+
bench.addEventListener('cycle', (event) => console.log(formatTaskResult(bench, event.task)))
33+
await bench.run()

0 commit comments

Comments
 (0)