mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 09:59:48 +02:00
Add benchmark for successive normalization
This commit is contained in:
19
perf/benchmarks/normalize-document-twice/index.js
Normal file
19
perf/benchmarks/normalize-document-twice/index.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
module.exports = {
|
||||||
|
run(state) {
|
||||||
|
const selection = state.selection.merge({
|
||||||
|
anchorKey: '_cursor_',
|
||||||
|
anchorOffset: 0,
|
||||||
|
focusKey: '_cursor_',
|
||||||
|
focusOffset: 0
|
||||||
|
})
|
||||||
|
|
||||||
|
return state
|
||||||
|
.transform({ normalized: false }).normalize().apply()
|
||||||
|
.transform()
|
||||||
|
// Make a fast, dummy change
|
||||||
|
.moveTo(selection).insertText('inserted text')
|
||||||
|
// We want to compare the speed of that second normalize (optimized through memoization, or other means)
|
||||||
|
.normalize().apply()
|
||||||
|
}
|
||||||
|
}
|
120
perf/benchmarks/normalize-document-twice/input.yaml
Normal file
120
perf/benchmarks/normalize-document-twice/input.yaml
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
nodes:
|
||||||
|
# Same than normalize-document-normal, but concatened 3 times
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
ranges:
|
||||||
|
- text: 'This is editable '
|
||||||
|
- text: 'rich'
|
||||||
|
marks:
|
||||||
|
- type: bold
|
||||||
|
- text: ' text, '
|
||||||
|
- text: 'much'
|
||||||
|
marks:
|
||||||
|
- type: italic
|
||||||
|
- text: ' better than a '
|
||||||
|
- text: '<textarea>'
|
||||||
|
marks:
|
||||||
|
- type: code
|
||||||
|
- text: '!'
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
key: '_cursor_'
|
||||||
|
ranges:
|
||||||
|
- text: 'Since it''s rich text, you can do things like turn a selection of text '
|
||||||
|
- text: 'bold'
|
||||||
|
marks:
|
||||||
|
- type: bold
|
||||||
|
- text: ', or add a semantically rendered block quote in the middle of the page,
|
||||||
|
like this:'
|
||||||
|
- kind: block
|
||||||
|
type: block-quote
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: 'A wise quote.'
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: 'Try it out for yourself!'
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
ranges:
|
||||||
|
- text: 'This is editable '
|
||||||
|
- text: 'rich'
|
||||||
|
marks:
|
||||||
|
- type: bold
|
||||||
|
- text: ' text, '
|
||||||
|
- text: 'much'
|
||||||
|
marks:
|
||||||
|
- type: italic
|
||||||
|
- text: ' better than a '
|
||||||
|
- text: '<textarea>'
|
||||||
|
marks:
|
||||||
|
- type: code
|
||||||
|
- text: '!'
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
ranges:
|
||||||
|
- text: 'Since it''s rich text, you can do things like turn a selection of text '
|
||||||
|
- text: 'bold'
|
||||||
|
marks:
|
||||||
|
- type: bold
|
||||||
|
- text: ', or add a semantically rendered block quote in the middle of the page,
|
||||||
|
like this:'
|
||||||
|
- kind: block
|
||||||
|
type: block-quote
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: 'A wise quote.'
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: 'Try it out for yourself!'
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
ranges:
|
||||||
|
- text: 'This is editable '
|
||||||
|
- text: 'rich'
|
||||||
|
marks:
|
||||||
|
- type: bold
|
||||||
|
- text: ' text, '
|
||||||
|
- text: 'much'
|
||||||
|
marks:
|
||||||
|
- type: italic
|
||||||
|
- text: ' better than a '
|
||||||
|
- text: '<textarea>'
|
||||||
|
marks:
|
||||||
|
- type: code
|
||||||
|
- text: '!'
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
ranges:
|
||||||
|
- text: 'Since it''s rich text, you can do things like turn a selection of text '
|
||||||
|
- text: 'bold'
|
||||||
|
marks:
|
||||||
|
- type: bold
|
||||||
|
- text: ', or add a semantically rendered block quote in the middle of the page,
|
||||||
|
like this:'
|
||||||
|
- kind: block
|
||||||
|
type: block-quote
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: 'A wise quote.'
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: 'Try it out for yourself!'
|
Reference in New Issue
Block a user