diff --git a/packages/slate-html-serializer/benchmark/index.js b/packages/slate-html-serializer/benchmark/index.js index 521d7c484..103cf99e9 100644 --- a/packages/slate-html-serializer/benchmark/index.js +++ b/packages/slate-html-serializer/benchmark/index.js @@ -13,8 +13,8 @@ const categories = fs.readdirSync(categoryDir).filter(c => c[0] != '.' && c != ' categories.forEach((category) => { suite(category, () => { - set('iterations', 100) - set('mintime', 2000) + set('iterations', 50) + set('mintime', 1000) if (category == 'models') { after(() => { diff --git a/packages/slate-plain-serializer/benchmark/index.js b/packages/slate-plain-serializer/benchmark/index.js index 521d7c484..103cf99e9 100644 --- a/packages/slate-plain-serializer/benchmark/index.js +++ b/packages/slate-plain-serializer/benchmark/index.js @@ -13,8 +13,8 @@ const categories = fs.readdirSync(categoryDir).filter(c => c[0] != '.' && c != ' categories.forEach((category) => { suite(category, () => { - set('iterations', 100) - set('mintime', 2000) + set('iterations', 50) + set('mintime', 1000) if (category == 'models') { after(() => { diff --git a/packages/slate-react/benchmark/index.js b/packages/slate-react/benchmark/index.js index 890800593..4d4c4c7c7 100644 --- a/packages/slate-react/benchmark/index.js +++ b/packages/slate-react/benchmark/index.js @@ -12,8 +12,8 @@ const categories = fs.readdirSync(categoryDir).filter(c => c[0] != '.' && c != ' categories.forEach((category) => { suite(category, () => { - set('iterations', 100) - set('mintime', 2000) + set('iterations', 50) + set('mintime', 1000) const benchmarkDir = resolve(categoryDir, category) const benchmarks = fs.readdirSync(benchmarkDir).filter(b => b[0] != '.' && !!~b.indexOf('.js')).map(b => basename(b, extname(b))) diff --git a/packages/slate/benchmark/changes/delete-backward.js b/packages/slate/benchmark/changes/delete-backward.js index c4508f565..c876d7d7e 100644 --- a/packages/slate/benchmark/changes/delete-backward.js +++ b/packages/slate/benchmark/changes/delete-backward.js @@ -3,10 +3,13 @@ import h from '../../test/helpers/h' -export default function (state) { - state - .change() - .deleteBackward() +export default function (change) { + change.deleteBackward() +} + +export function before(state) { + const change = state.change() + return change } export const input = ( diff --git a/packages/slate/benchmark/changes/delete-forward.js b/packages/slate/benchmark/changes/delete-forward.js new file mode 100644 index 000000000..c073f6285 --- /dev/null +++ b/packages/slate/benchmark/changes/delete-forward.js @@ -0,0 +1,30 @@ +/** @jsx h */ +/* eslint-disable react/jsx-key */ + +import h from '../../test/helpers/h' + +export default function (change) { + change.deleteForward() +} + +export function before(state) { + const change = state.change() + return change +} + +export const input = ( + + + {Array.from(Array(10)).map((v, i) => ( + + + + This is editable rich text, much better than a textarea! + {i == 0 ? : ''} + + + + ))} + + +) diff --git a/packages/slate/benchmark/changes/insert-text-by-key-multiple.js b/packages/slate/benchmark/changes/insert-text-by-key-multiple.js new file mode 100644 index 000000000..e79e518fe --- /dev/null +++ b/packages/slate/benchmark/changes/insert-text-by-key-multiple.js @@ -0,0 +1,35 @@ +/** @jsx h */ +/* eslint-disable react/jsx-key */ + +import h from '../../test/helpers/h' +import { __clear } from '../../lib/utils/memoize' + +export default function ({ change, keys }) { + for (const key of keys) { + change.insertTextByKey(key, 0, 'a') + } +} + +export function before(state) { + const change = state.change() + const keys = state.document.getTexts().toArray().map(t => t.key) + __clear() + return { change, keys } +} + +export const input = ( + + + {Array.from(Array(10)).map((v, i) => ( + + + + This is editable rich text, much better than a textarea! + {i == 0 ? : ''} + + + + ))} + + +) diff --git a/packages/slate/benchmark/changes/insert-text-by-key.js b/packages/slate/benchmark/changes/insert-text-by-key.js new file mode 100644 index 000000000..a4e70635a --- /dev/null +++ b/packages/slate/benchmark/changes/insert-text-by-key.js @@ -0,0 +1,33 @@ +/** @jsx h */ +/* eslint-disable react/jsx-key */ + +import h from '../../test/helpers/h' +import { __clear } from '../../lib/utils/memoize' + +export default function ({ change, text }) { + change.insertTextByKey(text.key, 0, 'a') +} + +export function before(state) { + const change = state.change() + const text = state.document.getLastText() + __clear() + return { change, text } +} + +export const input = ( + + + {Array.from(Array(10)).map((v, i) => ( + + + + This is editable rich text, much better than a textarea! + {i == 0 ? : ''} + + + + ))} + + +) diff --git a/packages/slate/benchmark/changes/insert-text.js b/packages/slate/benchmark/changes/insert-text.js index af68fc449..e70333fdf 100644 --- a/packages/slate/benchmark/changes/insert-text.js +++ b/packages/slate/benchmark/changes/insert-text.js @@ -3,10 +3,13 @@ import h from '../../test/helpers/h' -export default function (state) { - state - .change() - .insertText('a') +export default function (change) { + change.insertText('a') +} + +export function before(state) { + const change = state.change() + return change } export const input = ( diff --git a/packages/slate/benchmark/changes/split-block.js b/packages/slate/benchmark/changes/split-block.js index 40804fedb..c1a3fcf73 100644 --- a/packages/slate/benchmark/changes/split-block.js +++ b/packages/slate/benchmark/changes/split-block.js @@ -3,10 +3,13 @@ import h from '../../test/helpers/h' -export default function (state) { - state - .change() - .splitBlock() +export default function (change) { + change.splitBlock() +} + +export function before(state) { + const change = state.change() + return change } export const input = ( diff --git a/packages/slate/benchmark/index.js b/packages/slate/benchmark/index.js index 797676ca5..3b6eb11e5 100644 --- a/packages/slate/benchmark/index.js +++ b/packages/slate/benchmark/index.js @@ -14,7 +14,7 @@ const categories = fs.readdirSync(categoryDir).filter(c => c[0] != '.' && c != ' categories.forEach((category) => { suite(category, () => { set('iterations', 100) - set('mintime', 2000) + set('mintime', 1000) if (category == 'models') { after(() => { diff --git a/packages/slate/benchmark/models/has-node-multiple.js b/packages/slate/benchmark/models/has-node-multiple.js new file mode 100644 index 000000000..1b3330326 --- /dev/null +++ b/packages/slate/benchmark/models/has-node-multiple.js @@ -0,0 +1,33 @@ +/** @jsx h */ +/* eslint-disable react/jsx-key */ + +import h from '../../test/helpers/h' +import { __clear } from '../../lib/utils/memoize' + +export default function ({ state, keys }) { + keys.forEach((key) => { + state.document.hasNode(key) + }) +} + +export function before(state) { + const keys = state.document.getTexts().toArray().map(t => t.key) + __clear() + return { state, keys } +} + +export const input = ( + + + {Array.from(Array(10)).map(() => ( + + + + This is editable rich text, much better than a textarea! + + + + ))} + + +) diff --git a/packages/slate/benchmark/models/has-node.js b/packages/slate/benchmark/models/has-node.js new file mode 100644 index 000000000..12011d9c4 --- /dev/null +++ b/packages/slate/benchmark/models/has-node.js @@ -0,0 +1,31 @@ +/** @jsx h */ +/* eslint-disable react/jsx-key */ + +import h from '../../test/helpers/h' +import { __clear } from '../../lib/utils/memoize' + +export default function ({ state, text }) { + state.document.hasNode(text.key) +} + +export function before(state) { + const text = state.document.getLastText() + __clear() + return { state, text } +} + +export const input = ( + + + {Array.from(Array(10)).map(() => ( + + + + This is editable rich text, much better than a textarea! + + + + ))} + + +) diff --git a/support/benchmark-compare.js b/support/benchmark-compare.js index 2f610d2de..4afd34724 100644 --- a/support/benchmark-compare.js +++ b/support/benchmark-compare.js @@ -8,7 +8,7 @@ import comparison from '../tmp/benchmark-comparison' * Constants. */ -const THRESHOLD = 0.2 +const THRESHOLD = 0.333 /** * Print. @@ -24,14 +24,14 @@ baseline.forEach((suite, i) => { const comp = comparison[i].benchmarks[j] if (!comp) return - const b = base.iterations / base.elapsed * 100 - const c = comp.iterations / comp.elapsed * 100 + const b = base.iterations / base.elapsed * 1000 + const c = comp.iterations / comp.elapsed * 1000 const threshold = b * THRESHOLD const slower = (b - c) > threshold const faster = (b - c) < (0 - threshold) const percent = Math.round(Math.abs(b - c) / b * 100) - let output = `${b.toFixed(2)} → ${c.toFixed(2)} iterations/sec` + let output = `${b.toFixed(2)} → ${c.toFixed(2)} ops/sec` if (slower) output = chalk.red(`${output} (${percent}% slower)`) else if (faster) output = chalk.green(`${output} (${percent}% faster)`) else output = chalk.gray(output)