Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kk8787 committed Jul 3, 2024
1 parent 7b18677 commit 0c7041a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/proxyMap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,35 @@ describe('delete', () => {
})
})

describe('performance', () => {
it('should not be slow as linear growth', () => {
const state = proxyMap()

let operation100Time: number
{
const start = performance.now()
for (let i = 0; i < 100; i++) {
state.set(i, i)
}
const end = performance.now()
operation100Time = end - start
}

let operation1000Time: number
{
const start = performance.now()
for (let i = 0; i < 1000; i++) {
state.set(i, i)
}
const end = performance.now()
operation1000Time = end - start
}

const ratio = operation1000Time / operation100Time
expect(ratio).toBeLessThan(10)
})
})

describe('proxyMap internal', () => {
it('should be sealed', () => {
expect(Object.isSealed(proxySet())).toBe(true)
Expand Down
29 changes: 29 additions & 0 deletions tests/proxySet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,35 @@ describe('delete', () => {
})
})

describe('performance', () => {
it('should not be slow as linear growth', () => {
const state = proxySet()

let operation100Time: number
{
const start = performance.now()
for (let i = 0; i < 100; i++) {
state.add(i)
}
const end = performance.now()
operation100Time = end - start
}

let operation1000Time: number
{
const start = performance.now()
for (let i = 0; i < 1000; i++) {
state.add(i)
}
const end = performance.now()
operation1000Time = end - start
}

const ratio = operation1000Time / operation100Time
expect(ratio).toBeLessThan(10)
})
})

describe('proxySet internal', () => {
it('should be sealed', () => {
expect(Object.isSealed(proxySet())).toBe(true)
Expand Down

0 comments on commit 0c7041a

Please sign in to comment.