MCPcopy
hub / github.com/jquery/esprima / runParserTests

Function runParserTests

test/benchmark-parser.js:47–90  ·  view source on GitHub ↗
(tests)

Source from the content-addressed store, hash-verified

45}
46
47function runParserTests(tests) {
48 var tree = [],
49 totalTime = 0,
50 totalSize = 0,
51 totalRme = 0;
52
53 function pad(str, len) {
54 var result = str;
55 while (result.length < len) {
56 result = ' ' + result;
57 }
58 return result;
59 }
60
61 tests.reduce(function (suite, filename) {
62 var source = readFile(dirname + '/3rdparty/' + slug(filename) + '.js'),
63 size = source.length;
64 totalSize += size;
65 return suite.add(filename, function () {
66 var syntax = esprima.parse(source, { range: true, loc: true });
67 tree.push(syntax.body.length);
68 }, {
69 'onComplete': function (event) {
70 var result;
71 if (typeof gc === 'function') {
72 gc();
73 }
74 result = pad(this.name, 20);
75 result += pad(kb(size) + ' KiB', 12);
76 result += pad((1000 * this.stats.mean).toFixed(2), 10);
77 result += ' ms \xb1 ' + this.stats.rme.toFixed(2) + '%';
78 log(result);
79 totalTime += this.stats.mean;
80 totalRme += this.stats.mean * this.stats.rme * this.stats.rme;
81 }
82 });
83 }, new Benchmark.Suite()).on('complete', function () {
84 log(' ------------------------');
85 log(pad(kb(totalSize) + ' KiB', 32) +
86 pad((1000 * totalTime).toFixed(2), 10) + ' ms \xb1 ' +
87 Math.sqrt(totalRme / totalTime).toFixed(2) + '%'
88 );
89 }).run();
90}
91
92if (typeof require === 'undefined') {
93 dirname = 'test';

Callers 1

Calls 5

readFileFunction · 0.85
pushMethod · 0.80
slugFunction · 0.70
padFunction · 0.70
kbFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…