Skip to content

Commit

Permalink
add performance for lastIndexCase
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyraoul committed Nov 11, 2023
1 parent ec5db59 commit 209acea
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/mobx/__tests__/perf/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,41 @@ results of this test:
t.end()
})

test(`${version} - array.es2023 findLastIndex methods`, function (t) {
gc()
let aCalc = 0
let bCalc = 0
const ar = observable([0])
const findLastIndexOfZero = computed(function () {
aCalc++
return ar.findLastIndex(x => x === 0);
})
const lastIndexOfZero = computed(function () {
bCalc++
return ar.lastIndexOf(0);
})
mobx.observe(findLastIndexOfZero, voidObserver, true)
mobx.observe(lastIndexOfZero, voidObserver, true)

const start = now()

t.equal(1, aCalc)
t.equal(1, bCalc)
for (let i = 1; i < 10000; i++) ar.push(i)

t.equal(0, lastIndexOfZero.get())
t.equal(0, findLastIndexOfZero.get())
t.equal(10000, aCalc)
t.equal(10000, bCalc)

const end = now()

log(
"Array findLastIndex loop - Updated in " + (end - start) + " ms."
)
t.end()
})

test(`${version} - array reduce`, function (t) {
gc()
let aCalc = 0
Expand Down

0 comments on commit 209acea

Please sign in to comment.