Files
KaTeX/test/perf-test.js
ylemkimon 4178639ea5 Upgrade to Babel 7 (#1595)
* Upgrade to Babel 7

* Update dependencies

* Remove `modules` and `useEsModules` as module support is automatically detected

Target browsers supporting ESM in the ESM build.

* Disable corejs aliasing (polyfill)

* Fix package.json and update lockfile

* Bump CircleCI cache version

* Remove `Object.values()` use for Node 6 compatability

* Remove redundant arguments to @babel/register

* Update rollup and rollup-plugin-babel

* Add ignore option to no-transform-runtime-aliasing

Ignore JSON.stringify, parseInt, and ParseFloat

* Upgrade babel-loader to 8.0.1

* Use api.env() in Babel configuration

* Upgrade babel-loader to 8.0.2
2018-09-03 17:19:12 -04:00

60 lines
1.6 KiB
JavaScript

/* eslint-disable no-console */
/**
* Performance Tests
*
* This file measures the performance of renderToString using a number of strings
* from ss_data.yaml.
*
* TODO:
* - allow users to specify a different key or keys from ss_data.yaml
* - allow users to specify a different string or strings
* - provide a way to test the performance against different branches
*/
const Benchmark = require('benchmark');
const yaml = require('js-yaml');
const fs = require('fs');
const path = require('path');
const filename = path.resolve(__dirname, 'screenshotter/ss_data.yaml');
const data = yaml.load(fs.readFileSync(filename, 'utf-8'));
console.log('compiling katex...');
require('@babel/register');
const katex = require('../katex').default;
console.log('');
// Benchmark is a performancing testing library. It allows you to define a
// suite of tests. After adding tests to the suite with the .add() method they
// can be run by calling the .run() method. See https://benchmarkjs.com.
const suite = new Benchmark.Suite;
const testsToRun = [
"AccentsText",
"ArrayMode",
"GroupMacros",
"MathBb",
"SqrtRoot",
"StretchyAccent",
"Units",
];
for (const key of testsToRun) {
const value = data[key];
if (typeof value === "string") {
suite.add(key, () => katex.renderToString(value));
} else {
const options = {
macros: value.macros,
};
suite.add(key, () => katex.renderToString(value.tex, options));
}
}
// Print out the ops/sec for each test
suite.on('cycle', function(event) {
console.log(String(event.target));
});
const config = {};
suite.run(config);