From 4f3a2c0c5f55b6c638cbc4dd369567e867ff7c97 Mon Sep 17 00:00:00 2001 From: Alfred Melch Date: Tue, 6 Aug 2019 17:23:40 +0200 Subject: [PATCH] lazy loading of datasets --- benchmarking/src/components/chart.js | 24 ++++++++++++++---------- benchmarking/src/components/form.js | 12 ++++++++---- benchmarking/src/components/runner.js | 14 ++++++++------ benchmarking/src/data/index.js | 21 +++++++++++++++++---- benchmarking/src/simplifyMapper.js | 2 +- 5 files changed, 48 insertions(+), 25 deletions(-) diff --git a/benchmarking/src/components/chart.js b/benchmarking/src/components/chart.js index 37ad874..f792276 100644 --- a/benchmarking/src/components/chart.js +++ b/benchmarking/src/components/chart.js @@ -4,6 +4,8 @@ import debounceRender from 'react-debounce-render' import platform from 'platform' import { downloadAsJson } from '../../../lib/json-download/index.js' + +import { datasetNames } from '../data/index.js' import { datasetTemplates, genOptions, beautifyLabels } from './chartOptions.js' export class Chart extends React.Component { @@ -11,7 +13,6 @@ export class Chart extends React.Component { let { formState, stats, nodeData } = this.props let { tolRange, chart } = formState tolRange = tolRange || [] - let labels = beautifyLabels(tolRange) // let labels = tolRange.map(x => Math.round(x * 1000) / 1000) let datasets = Object.keys(stats).map(name => ({ @@ -19,15 +20,9 @@ export class Chart extends React.Component { data: stats[name] })) datasets.push({ ...datasetTemplates.numberOfNodes, data: nodeData }) - datasets.push({ - label: `High quality mode: ${formState.highQual}`, - data: [] - }) - datasets.push({ - label: `Platform: ${platform.description}`, - data: [] - }) let data = { datasets, labels } + addLegendEntry(data, `High quality mode: ${formState.highQual}`) + addLegendEntry(data, `Platform: ${platform.description}`) return (

Chart

@@ -117,7 +112,7 @@ function calculateTimeDelta(whole, arr1, arr2) { } function modifyDataArrays(data, exec, pre, after, newDatasetLabel) { - if (getDataset(data, exec)) { + if (getDataset(data, exec) && getDataset(data, pre)) { data.datasets.splice(1, 0, { id: 'execution', backgroundColor: 'red', @@ -208,3 +203,12 @@ function saveChart(chartRef) { ) downloadAsJson(config, 'config.json') } + +/** + * Adds an empty dataset to attach info to legend + * @param {} data + * @param {*} label + */ +function addLegendEntry(data, label) { + data.datasets.push({ label, data: [] }) +} diff --git a/benchmarking/src/components/form.js b/benchmarking/src/components/form.js index 0e22d2c..ba99df2 100644 --- a/benchmarking/src/components/form.js +++ b/benchmarking/src/components/form.js @@ -1,5 +1,7 @@ import React, { Component } from 'react' +import { datasetNames } from '../data/index.js' + export class Form extends Component { constructor(props) { super(props) @@ -12,7 +14,7 @@ export class Form extends Component { benchMethod: 'iteration', iterations: 10, timeToRun: 200, - dataset: 'large', + dataset: Object.keys(datasetNames)[0], debouncedChart: false } @@ -56,9 +58,11 @@ export class Form extends Component { value={this.state.dataset} onChange={this.handleInputChange} > - - - + {Object.keys(datasetNames).map((key, idx) => ( + + ))} diff --git a/benchmarking/src/components/runner.js b/benchmarking/src/components/runner.js index 3a96850..26a13cd 100644 --- a/benchmarking/src/components/runner.js +++ b/benchmarking/src/components/runner.js @@ -33,18 +33,20 @@ export class BenchmarkRunner extends Component { this.props.onStatsChange(this.suite.stats) } - componentDidUpdate(prevProps, prevState) { + async componentDidUpdate(prevProps, prevState) { if (prevState !== this.state) { + // state changed -> internal update this.props.onStatsChange(this.suite.stats) } if (prevProps.formState !== this.props.formState) { - this.initializeSuite() + // props changed -> update from parent + await this.initializeSuite() this.suite.stop() } } - initializeSuite() { - let data = dataSelector[this.props.formState.dataset] + async initializeSuite() { + let data = await dataSelector(this.props.formState.dataset) this.suite.setBenchmarkType(benchmarkTypeSelector(this.props.formState)) this.suite.setCases(generateCases(data, this.props.formState)) } @@ -87,8 +89,8 @@ export class BenchmarkRunner extends Component { {this.startButtonShown() && (