Files
KaTeX/test/perf-test.js
2018-01-29 20:38:14 -05: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
*/
require('babel-register');
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...');
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);