reactiveObject.bench.ts 589 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { bench } from 'vitest'
  2. import { reactive } from '../dist/reactivity.esm-browser.prod'
  3. bench('create reactive obj', () => {
  4. reactive({ a: 1 })
  5. })
  6. {
  7. const raw = { a: 1 }
  8. reactive(raw)
  9. bench('return cached reactive obj', () => {
  10. reactive(raw)
  11. })
  12. }
  13. {
  14. const r = reactive({ a: 1 })
  15. bench('read reactive obj property', () => {
  16. r.a
  17. })
  18. }
  19. {
  20. const r = reactive({ a: { b: 1 } })
  21. bench('read nested reactive obj property', () => {
  22. r.a.b
  23. })
  24. }
  25. {
  26. let i = 0
  27. const r = reactive({ a: 1 })
  28. bench('write reactive obj property', () => {
  29. r.a = i++
  30. })
  31. }