123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- /* 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);
|