1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-06 05:49:47 +01:00
Ian Storm Taylor 059ee96db8 a handful of performance improvements ()
* update large example

* pass block down to <Text> for performance, closes 

* add get-ranges benchmark

* optimize getRanges(), closes 

* add serialization benchmarks

* optimize Raw.deserializeRanges() by computing marks once, closes 

* change .merge calls to .set for performance

* change updateDescendant() to use getAncestors() for memoization

* change getPath() to use getAncestors() for memoization

* switch getTexts() and friends to use arrays while iterating

* rename split-block benchmark

* update benchmark compare script
2017-04-02 14:57:36 -07:00

44 lines
1.0 KiB
JavaScript

/* eslint-disable no-console */
import chalk from 'chalk'
import baseline from '../tmp/benchmark-baseline'
import comparison from '../tmp/benchmark-comparison'
/**
* Constants.
*/
const THRESHOLD = 0.2
/**
* Print.
*/
console.log()
console.log(` benchmarks`)
baseline.forEach((suite, i) => {
console.log(` ${suite.name}`)
suite.benchmarks.forEach((base, j) => {
const comp = comparison[i].benchmarks[j]
if (!comp) return
const b = base.iterations / base.elapsed * 100
const c = comp.iterations / comp.elapsed * 100
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`
if (slower) output = chalk.red(`${output} (${percent}% slower)`)
if (faster) output = chalk.green(`${output} (${percent}% faster)`)
console.log(` ${base.title}`)
console.log(` ${output}`)
})
})
console.log()