showdown/test/node/performance.js

150 lines
4.9 KiB
JavaScript
Raw Normal View History

2016-12-23 17:29:58 +08:00
/**
* Created by Tivie on 21/12/2016.
*/
'use strict';
var fs = require('fs'),
showdown = require('../bootstrap').showdown,
converter = new showdown.Converter(),
pkg = require('../../package.json'),
performance = require('../performance/performance.js');
performance.setLibraryName(pkg.name);
performance.setVersion(pkg.version);
performance.setGithubLink('https://github.com/showdownjs/showdown/tree/');
2016-12-23 18:07:14 +08:00
var globals = {
gHtmlBlocks: [],
gHtmlMdBlocks: [],
gHtmlSpans: [],
gUrls: {},
gTitles: {},
gDimensions: {},
gListLevel: 0,
hashLinkCounts: {},
langExtensions: [],
outputModifiers: [],
converter: converter,
ghCodeBlocks: []
},
options = showdown.getOptions();
function runTests() {
var testMDFile = fs.readFileSync('test/performance.testfile.md', 'utf8');
2016-12-23 18:07:14 +08:00
new performance.Suite('Basic')
2017-01-28 10:04:50 +08:00
.setOption('cycles', 50)
2016-12-23 18:07:14 +08:00
.add('Simple "Hello World"', function () {
converter.makeHtml('*Hello* **World**!');
})
2017-01-28 10:53:25 +08:00
.add('performance.testfile.md', {
2016-12-23 18:07:14 +08:00
prepare: function () {
return testMDFile;
2016-12-23 18:07:14 +08:00
},
test: function (mdText) {
converter.makeHtml(mdText);
}
});
new performance.Suite('subParsers')
2017-01-28 10:04:50 +08:00
.setOption('cycles', 20)
2016-12-23 18:07:14 +08:00
.add('hashHTMLBlocks', function () {
showdown.subParser('hashHTMLBlocks')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('anchors', function () {
showdown.subParser('anchors')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('autoLinks', function () {
showdown.subParser('autoLinks')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
/*
2016-12-23 18:07:14 +08:00
.add('blockGamut', function () {
showdown.subParser('blockGamut')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
*/
2016-12-23 18:07:14 +08:00
.add('blockQuotes', function () {
showdown.subParser('blockQuotes')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('codeBlocks', function () {
showdown.subParser('codeBlocks')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('codeSpans', function () {
showdown.subParser('codeSpans')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('detab', function () {
showdown.subParser('detab')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('encodeAmpsAndAngles', function () {
showdown.subParser('encodeAmpsAndAngles')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('encodeBackslashEscapes', function () {
showdown.subParser('encodeBackslashEscapes')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('encodeCode', function () {
showdown.subParser('encodeCode')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('escapeSpecialCharsWithinTagAttributes', function () {
showdown.subParser('escapeSpecialCharsWithinTagAttributes')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('githubCodeBlocks', function () {
showdown.subParser('githubCodeBlocks')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('hashBlock', function () {
showdown.subParser('hashBlock')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('hashElement', function () {
showdown.subParser('hashElement')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('hashHTMLSpans', function () {
showdown.subParser('hashHTMLSpans')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('hashPreCodeTags', function () {
showdown.subParser('hashPreCodeTags')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('headers', function () {
showdown.subParser('headers')(testMDFile, options, globals);
})
.add('horizontalRule', function () {
showdown.subParser('horizontalRule')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('images', function () {
showdown.subParser('images')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('italicsAndBold', function () {
showdown.subParser('italicsAndBold')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('lists', function () {
showdown.subParser('lists')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('outdent', function () {
showdown.subParser('outdent')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('paragraphs', function () {
showdown.subParser('paragraphs')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('spanGamut', function () {
showdown.subParser('spanGamut')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('strikethrough', function () {
showdown.subParser('strikethrough')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('stripBlankLines', function () {
showdown.subParser('stripBlankLines')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('stripLinkDefinitions', function () {
showdown.subParser('stripLinkDefinitions')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('tables', function () {
showdown.subParser('tables')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
})
.add('unescapeSpecialChars', function () {
showdown.subParser('unescapeSpecialChars')(testMDFile, options, globals);
2016-12-23 18:07:14 +08:00
});
}
function generateLogs () {
performance.generateLog(null, null, true);
}
2016-12-23 17:29:58 +08:00
module.exports = {
runTests: runTests,
generateLogs: generateLogs
};