mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 10:29:48 +02:00
add benchmarks, update benchmark reporting
This commit is contained in:
@@ -13,8 +13,8 @@ const categories = fs.readdirSync(categoryDir).filter(c => c[0] != '.' && c != '
|
|||||||
|
|
||||||
categories.forEach((category) => {
|
categories.forEach((category) => {
|
||||||
suite(category, () => {
|
suite(category, () => {
|
||||||
set('iterations', 100)
|
set('iterations', 50)
|
||||||
set('mintime', 2000)
|
set('mintime', 1000)
|
||||||
|
|
||||||
if (category == 'models') {
|
if (category == 'models') {
|
||||||
after(() => {
|
after(() => {
|
||||||
|
@@ -13,8 +13,8 @@ const categories = fs.readdirSync(categoryDir).filter(c => c[0] != '.' && c != '
|
|||||||
|
|
||||||
categories.forEach((category) => {
|
categories.forEach((category) => {
|
||||||
suite(category, () => {
|
suite(category, () => {
|
||||||
set('iterations', 100)
|
set('iterations', 50)
|
||||||
set('mintime', 2000)
|
set('mintime', 1000)
|
||||||
|
|
||||||
if (category == 'models') {
|
if (category == 'models') {
|
||||||
after(() => {
|
after(() => {
|
||||||
|
@@ -12,8 +12,8 @@ const categories = fs.readdirSync(categoryDir).filter(c => c[0] != '.' && c != '
|
|||||||
|
|
||||||
categories.forEach((category) => {
|
categories.forEach((category) => {
|
||||||
suite(category, () => {
|
suite(category, () => {
|
||||||
set('iterations', 100)
|
set('iterations', 50)
|
||||||
set('mintime', 2000)
|
set('mintime', 1000)
|
||||||
|
|
||||||
const benchmarkDir = resolve(categoryDir, category)
|
const benchmarkDir = resolve(categoryDir, category)
|
||||||
const benchmarks = fs.readdirSync(benchmarkDir).filter(b => b[0] != '.' && !!~b.indexOf('.js')).map(b => basename(b, extname(b)))
|
const benchmarks = fs.readdirSync(benchmarkDir).filter(b => b[0] != '.' && !!~b.indexOf('.js')).map(b => basename(b, extname(b)))
|
||||||
|
@@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
|
|
||||||
export default function (state) {
|
export default function (change) {
|
||||||
state
|
change.deleteBackward()
|
||||||
.change()
|
}
|
||||||
.deleteBackward()
|
|
||||||
|
export function before(state) {
|
||||||
|
const change = state.change()
|
||||||
|
return change
|
||||||
}
|
}
|
||||||
|
|
||||||
export const input = (
|
export const input = (
|
||||||
|
30
packages/slate/benchmark/changes/delete-forward.js
Normal file
30
packages/slate/benchmark/changes/delete-forward.js
Normal file
@@ -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 = (
|
||||||
|
<state>
|
||||||
|
<document>
|
||||||
|
{Array.from(Array(10)).map((v, i) => (
|
||||||
|
<quote>
|
||||||
|
<paragraph>
|
||||||
|
<paragraph>
|
||||||
|
This is editable <b>rich</b> text, <i>much</i> better than a textarea!
|
||||||
|
{i == 0 ? <cursor /> : ''}
|
||||||
|
</paragraph>
|
||||||
|
</paragraph>
|
||||||
|
</quote>
|
||||||
|
))}
|
||||||
|
</document>
|
||||||
|
</state>
|
||||||
|
)
|
@@ -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 = (
|
||||||
|
<state>
|
||||||
|
<document>
|
||||||
|
{Array.from(Array(10)).map((v, i) => (
|
||||||
|
<quote>
|
||||||
|
<paragraph>
|
||||||
|
<paragraph>
|
||||||
|
This is editable <b>rich</b> text, <i>much</i> better than a textarea!
|
||||||
|
{i == 0 ? <cursor /> : ''}
|
||||||
|
</paragraph>
|
||||||
|
</paragraph>
|
||||||
|
</quote>
|
||||||
|
))}
|
||||||
|
</document>
|
||||||
|
</state>
|
||||||
|
)
|
33
packages/slate/benchmark/changes/insert-text-by-key.js
Normal file
33
packages/slate/benchmark/changes/insert-text-by-key.js
Normal file
@@ -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 = (
|
||||||
|
<state>
|
||||||
|
<document>
|
||||||
|
{Array.from(Array(10)).map((v, i) => (
|
||||||
|
<quote>
|
||||||
|
<paragraph>
|
||||||
|
<paragraph>
|
||||||
|
This is editable <b>rich</b> text, <i>much</i> better than a textarea!
|
||||||
|
{i == 0 ? <cursor /> : ''}
|
||||||
|
</paragraph>
|
||||||
|
</paragraph>
|
||||||
|
</quote>
|
||||||
|
))}
|
||||||
|
</document>
|
||||||
|
</state>
|
||||||
|
)
|
@@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
|
|
||||||
export default function (state) {
|
export default function (change) {
|
||||||
state
|
change.insertText('a')
|
||||||
.change()
|
}
|
||||||
.insertText('a')
|
|
||||||
|
export function before(state) {
|
||||||
|
const change = state.change()
|
||||||
|
return change
|
||||||
}
|
}
|
||||||
|
|
||||||
export const input = (
|
export const input = (
|
||||||
|
@@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
import h from '../../test/helpers/h'
|
import h from '../../test/helpers/h'
|
||||||
|
|
||||||
export default function (state) {
|
export default function (change) {
|
||||||
state
|
change.splitBlock()
|
||||||
.change()
|
}
|
||||||
.splitBlock()
|
|
||||||
|
export function before(state) {
|
||||||
|
const change = state.change()
|
||||||
|
return change
|
||||||
}
|
}
|
||||||
|
|
||||||
export const input = (
|
export const input = (
|
||||||
|
@@ -14,7 +14,7 @@ const categories = fs.readdirSync(categoryDir).filter(c => c[0] != '.' && c != '
|
|||||||
categories.forEach((category) => {
|
categories.forEach((category) => {
|
||||||
suite(category, () => {
|
suite(category, () => {
|
||||||
set('iterations', 100)
|
set('iterations', 100)
|
||||||
set('mintime', 2000)
|
set('mintime', 1000)
|
||||||
|
|
||||||
if (category == 'models') {
|
if (category == 'models') {
|
||||||
after(() => {
|
after(() => {
|
||||||
|
33
packages/slate/benchmark/models/has-node-multiple.js
Normal file
33
packages/slate/benchmark/models/has-node-multiple.js
Normal file
@@ -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 = (
|
||||||
|
<state>
|
||||||
|
<document>
|
||||||
|
{Array.from(Array(10)).map(() => (
|
||||||
|
<quote>
|
||||||
|
<paragraph>
|
||||||
|
<paragraph>
|
||||||
|
This is editable <b>rich</b> text, <i>much</i> better than a textarea!
|
||||||
|
</paragraph>
|
||||||
|
</paragraph>
|
||||||
|
</quote>
|
||||||
|
))}
|
||||||
|
</document>
|
||||||
|
</state>
|
||||||
|
)
|
31
packages/slate/benchmark/models/has-node.js
Normal file
31
packages/slate/benchmark/models/has-node.js
Normal file
@@ -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 = (
|
||||||
|
<state>
|
||||||
|
<document>
|
||||||
|
{Array.from(Array(10)).map(() => (
|
||||||
|
<quote>
|
||||||
|
<paragraph>
|
||||||
|
<paragraph>
|
||||||
|
This is editable <b>rich</b> text, <i>much</i> better than a textarea!
|
||||||
|
</paragraph>
|
||||||
|
</paragraph>
|
||||||
|
</quote>
|
||||||
|
))}
|
||||||
|
</document>
|
||||||
|
</state>
|
||||||
|
)
|
@@ -8,7 +8,7 @@ import comparison from '../tmp/benchmark-comparison'
|
|||||||
* Constants.
|
* Constants.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const THRESHOLD = 0.2
|
const THRESHOLD = 0.333
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print.
|
* Print.
|
||||||
@@ -24,14 +24,14 @@ baseline.forEach((suite, i) => {
|
|||||||
const comp = comparison[i].benchmarks[j]
|
const comp = comparison[i].benchmarks[j]
|
||||||
if (!comp) return
|
if (!comp) return
|
||||||
|
|
||||||
const b = base.iterations / base.elapsed * 100
|
const b = base.iterations / base.elapsed * 1000
|
||||||
const c = comp.iterations / comp.elapsed * 100
|
const c = comp.iterations / comp.elapsed * 1000
|
||||||
const threshold = b * THRESHOLD
|
const threshold = b * THRESHOLD
|
||||||
const slower = (b - c) > threshold
|
const slower = (b - c) > threshold
|
||||||
const faster = (b - c) < (0 - threshold)
|
const faster = (b - c) < (0 - threshold)
|
||||||
const percent = Math.round(Math.abs(b - c) / b * 100)
|
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)`)
|
if (slower) output = chalk.red(`${output} (${percent}% slower)`)
|
||||||
else if (faster) output = chalk.green(`${output} (${percent}% faster)`)
|
else if (faster) output = chalk.green(`${output} (${percent}% faster)`)
|
||||||
else output = chalk.gray(output)
|
else output = chalk.gray(output)
|
||||||
|
Reference in New Issue
Block a user