-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up a performance testing pipeline
- Loading branch information
1 parent
36591c6
commit cab36a4
Showing
4 changed files
with
194 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Compile-Eval-Render Pipeline for Intervals | ||
|
||
> Summary of the render process that happens on every tick (pan/zoom) in the graph. | ||
As of v1.24.0 the render pipeline consists of: | ||
|
||
- Compile + Eval | ||
- compile `fn` to a *-eval function (see [interval-arithmetic-eval](https://github.com/mauriciopoppe/interval-arithmetic-eval) | ||
or [built-in-math-eval](https://github.com/mauriciopoppe/built-in-math-eval)) | ||
- The [above is cached]() so that when `functionPlot` is invoked it isn't | ||
the compilation isn't run many times. | ||
- [use `nSamples`](https://github.com/mauriciopoppe/function-plot/blob/b46e07c3281bce5b6bff00050ba3d6a16795a483/src/evaluate.ts#L40) | ||
to create [`nSamples` equally distinct points](https://github.com/mauriciopoppe/function-plot/blob/b46e07c3281bce5b6bff00050ba3d6a16795a483/src/samplers/interval.ts#L17), | ||
e.g. `[x_0, x_1, ..., x_{n_samples - 1}]` | ||
- In `O(n)`, iterate over all the points and evaluate each them against the compiled function evaluator (created in the preparation stage), | ||
return a data structure that encodes the result (`Array<Array<[Interval, Interval]> | null>`) | ||
- Render | ||
- In `O(n)` iterate over all the results and create a [`<path d={rectanglePaint} />`](https://github.com/mauriciopoppe/function-plot/blob/b46e07c3281bce5b6bff00050ba3d6a16795a483/src/graph-types/interval.ts#L96) | ||
where `rectanglePaint` is a [series of commands](https://github.com/mauriciopoppe/function-plot/blob/b46e07c3281bce5b6bff00050ba3d6a16795a483/src/graph-types/interval.ts#L68) | ||
of the form `M <x> <y> v <width>` which move to `(x, y)` and paint a rectangle of width `width`. | ||
|
||
## Perf stats | ||
|
||
Using `npm run perf:pipeline`: | ||
|
||
``` | ||
compile and eval 1000 x 1,163 ops/sec ±0.26% (98 runs sampled) | ||
compile and eval 1000 x 1,172 ops/sec ±0.46% (97 runs sampled) | ||
compile and eval 1000 x 1,164 ops/sec ±0.23% (96 runs sampled) | ||
drawPath 1000 x 8,398 ops/sec ±0.58% (99 runs sampled) | ||
drawPath 1000 x 8,392 ops/sec ±0.53% (97 runs sampled) | ||
drawPath 1000 x 8,266 ops/sec ±0.55% (96 runs sampled) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* interval-pipeline evaluates the performance of the compile, eval, render pipeline, | ||
* the design is at /design/pipeline.md | ||
*/ | ||
|
||
// @ts-ignore | ||
import Benchmark from 'benchmark' | ||
import { scaleLinear } from 'd3-scale' | ||
|
||
import { FunctionPlotDatum, FunctionPlotOptionsAxis } from '../types' | ||
import { createPathD } from '../graph-types/interval' | ||
import interval from '../samplers/interval' | ||
|
||
function createData(nSamples: number) { | ||
const width = 500 | ||
const height = 300 | ||
const xDomain: [number, number] = [-5, 5] | ||
const yDomain: [number, number] = [-5, 5] | ||
const xScale = scaleLinear().domain(xDomain).range([0, width]) | ||
const yScale = scaleLinear().domain(yDomain).range([height, 0]) | ||
const d: FunctionPlotDatum = { | ||
fn: '1/x', | ||
fnType: 'linear' | ||
} | ||
const xAxis: FunctionPlotOptionsAxis = { type: 'linear' } | ||
const yAxis: FunctionPlotOptionsAxis = { type: 'linear' } | ||
const samplerParams = { | ||
d, | ||
range: xDomain, | ||
xScale, | ||
yScale, | ||
xAxis, | ||
yAxis, | ||
nSamples | ||
} | ||
const data = interval(samplerParams) | ||
return { data, xScale, yScale } | ||
} | ||
|
||
function compileAndEval() { | ||
const compileAndEval = new Benchmark.Suite() | ||
const nSamples = 1000 | ||
compileAndEval | ||
.add(`compile and eval ${nSamples}`, function () { | ||
createData(nSamples) | ||
}) | ||
// add listeners | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')) | ||
}) | ||
.run({ async: false }) | ||
} | ||
|
||
function drawPath() { | ||
const compileAndEval = new Benchmark.Suite() | ||
const nSamples = 1000 | ||
const { xScale, yScale, data } = createData(nSamples) | ||
compileAndEval | ||
.add(`drawPath ${nSamples}`, function () { | ||
createPathD(xScale, yScale, 1 /* minWidthHeight, dummy = 1 */, data[0], false /* closed */) | ||
}) | ||
// add listeners | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')) | ||
}) | ||
.run({ async: false }) | ||
} | ||
|
||
function main() { | ||
compileAndEval() | ||
drawPath() | ||
} | ||
|
||
main() |