Skip to content

Commit

Permalink
bench tree2
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Oct 14, 2024
1 parent df4a180 commit 59768aa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/vanilla/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export { watch } from './utils/watch.ts'
export { devtools } from './utils/devtools.ts'
export { deepClone } from './utils/deepClone.ts'
export { proxySet } from './utils/proxySet.ts'
export { proxyMap } from './utils/proxyMap-tree2.ts'
export { proxyMap } from './utils/proxyMap.ts'

export { proxyMap as proxyMapTree2 } from './utils/proxyMap-tree2.ts'
42 changes: 30 additions & 12 deletions tests/proxyMap.bench.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable vitest/consistent-test-it */
import { bench, describe, test } from 'vitest'
import { snapshot } from 'valtio'
import { proxyMap } from 'valtio/utils'
import { proxyMap, proxyMapTree2 } from 'valtio/utils'

// Helper function to generate test data
function generateTestData(size: number): [number, number][] {
Expand All @@ -12,10 +12,10 @@ function generateTestData(size: number): [number, number][] {
return data
}

const TEST_SIZES = [1000]
const TEST_SIZES = [1000, 10_000]

TEST_SIZES.forEach((size) => {
describe(`Insertion -${size} items`, () => {
describe.skip(`Insertion -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -26,7 +26,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`Insertion and Update -${size} items`, () => {
describe.skip(`Insertion and Update -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -38,7 +38,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`Retrieval -${size} items`, () => {
describe.skip(`Retrieval -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -49,7 +49,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`Deletion -${size} items`, () => {
describe.skip(`Deletion -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -60,7 +60,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`Iteration -${size} items`, () => {
describe.skip(`Iteration -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -69,7 +69,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`Insertion, Retrieval, and Deletion -${size} items`, () => {
describe.skip(`Insertion, Retrieval, and Deletion -${size} items`, () => {
const testData = generateTestData(size)
bench('proxyMap', () => {
const map = proxyMap<number, number>(testData)
Expand All @@ -81,7 +81,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`entries -${size} items`, () => {
describe.skip(`entries -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -93,7 +93,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`keys -${size} items`, () => {
describe.skip(`keys -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -104,7 +104,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`values -${size} items`, () => {
describe.skip(`values -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -115,7 +115,7 @@ TEST_SIZES.forEach((size) => {
})
})

describe(`snapshot -${size} items`, () => {
describe.skip(`snapshot -${size} items`, () => {
const testData = generateTestData(size)

bench('proxyMap', () => {
Expand All @@ -126,4 +126,22 @@ TEST_SIZES.forEach((size) => {
})
})
})

describe(`snapshot & modify -${size} items`, () => {
const testData = generateTestData(size)
const oneData = generateTestData(1)[0]!

bench('proxyMap', () => {
const map = proxyMap<number, number>(testData)
const snap1 = snapshot(map)
map.set(oneData[0], oneData[1])
const snap2 = snapshot(map)
})
bench('proxyMapTree2', () => {
const map = proxyMapTree2<number, number>(testData)
const snap1 = snapshot(map)
map.set(oneData[0], oneData[1])
const snap2 = snapshot(map)
})
})
})

0 comments on commit 59768aa

Please sign in to comment.