2016-12-23 17:29:58 +08:00
|
|
|
/**
|
|
|
|
* Created by Tivie on 21/12/2016.
|
|
|
|
*/
|
|
|
|
'use strict';
|
2017-12-22 23:28:41 +08:00
|
|
|
var fs = require('fs'),
|
|
|
|
showdown = require('../../.build/showdown.js'),
|
|
|
|
converter = new showdown.Converter(),
|
|
|
|
pkg = require('../../package.json'),
|
|
|
|
performance = require('./lib/performance.lib.js');
|
|
|
|
|
|
|
|
performance.setLibraryName(pkg.name);
|
|
|
|
performance.setVersion(pkg.version);
|
|
|
|
performance.setGithubLink('https://github.com/showdownjs/showdown/tree/');
|
|
|
|
|
|
|
|
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');
|
|
|
|
new performance.Suite('Basic')
|
|
|
|
.setOption('cycles', 50)
|
|
|
|
.add('Simple "Hello World"', function () {
|
|
|
|
converter.makeHtml('*Hello* **World**!');
|
|
|
|
})
|
|
|
|
.add('performance.testfile.md', {
|
|
|
|
prepare: function () {
|
|
|
|
return testMDFile;
|
|
|
|
},
|
|
|
|
test: function (mdText) {
|
|
|
|
converter.makeHtml(mdText);
|
2016-12-23 17:29:58 +08:00
|
|
|
}
|
|
|
|
});
|
2017-12-22 23:28:41 +08:00
|
|
|
new performance.Suite('subParsers')
|
|
|
|
.setOption('cycles', 20)
|
|
|
|
.add('hashHTMLBlocks', function () {
|
|
|
|
showdown.subParser('makehtml.hashHTMLBlocks')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('anchors', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.link')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('blockQuotes', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.blockquote')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('codeBlocks', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.codeBlock')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('codeSpans', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.codeSpan')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('encodeAmpsAndAngles', function () {
|
|
|
|
showdown.subParser('makehtml.encodeAmpsAndAngles')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('encodeBackslashEscapes', function () {
|
|
|
|
showdown.subParser('makehtml.encodeBackslashEscapes')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('encodeCode', function () {
|
|
|
|
showdown.subParser('makehtml.encodeCode')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('escapeSpecialCharsWithinTagAttributes', function () {
|
|
|
|
showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('githubCodeBlocks', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.githubCodeBlock')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('hashBlock', function () {
|
|
|
|
showdown.subParser('makehtml.hashBlock')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('hashElement', function () {
|
|
|
|
showdown.subParser('makehtml.hashElement')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('hashHTMLSpans', function () {
|
|
|
|
showdown.subParser('makehtml.hashHTMLSpans')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('hashPreCodeTags', function () {
|
|
|
|
showdown.subParser('makehtml.hashPreCodeTags')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('headers', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.heading')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('horizontalRule', function () {
|
|
|
|
showdown.subParser('makehtml.horizontalRule')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('images', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.image')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('italicsAndBold', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.emphasisAndStrong')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('lists', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.list')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('paragraphs', function () {
|
|
|
|
showdown.subParser('makehtml.paragraphs')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('spanGamut', function () {
|
|
|
|
showdown.subParser('makehtml.spanGamut')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('strikethrough', function () {
|
|
|
|
showdown.subParser('makehtml.strikethrough')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('stripLinkDefinitions', function () {
|
|
|
|
showdown.subParser('makehtml.stripLinkDefinitions')(testMDFile, options, globals);
|
|
|
|
})
|
|
|
|
.add('tables', function () {
|
2022-05-08 01:59:09 +08:00
|
|
|
showdown.subParser('makehtml.table')(testMDFile, options, globals);
|
2017-12-22 23:28:41 +08:00
|
|
|
})
|
|
|
|
.add('unescapeSpecialChars', function () {
|
|
|
|
showdown.subParser('makehtml.unescapeSpecialChars')(testMDFile, options, globals);
|
|
|
|
});
|
|
|
|
}
|
2016-12-23 17:29:58 +08:00
|
|
|
|
2017-12-22 23:28:41 +08:00
|
|
|
function generateLogs () {
|
|
|
|
performance.generateLog(null, null, true);
|
|
|
|
}
|
2016-12-23 17:29:58 +08:00
|
|
|
|
2017-12-22 23:28:41 +08:00
|
|
|
module.exports = {
|
|
|
|
runTests: runTests,
|
|
|
|
generateLogs: generateLogs
|
2016-12-23 17:29:58 +08:00
|
|
|
};
|