forked from KaTeX/KaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf-test.js
59 lines (52 loc) · 1.62 KB
/
perf-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* 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);