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 = {
|
2017-01-31 13:46:25 +08:00
|
|
|
gHtmlBlocks: [],
|
|
|
|
gHtmlMdBlocks: [],
|
|
|
|
gHtmlSpans: [],
|
|
|
|
gUrls: {},
|
|
|
|
gTitles: {},
|
|
|
|
gDimensions: {},
|
|
|
|
gListLevel: 0,
|
|
|
|
hashLinkCounts: {},
|
|
|
|
langExtensions: [],
|
|
|
|
outputModifiers: [],
|
|
|
|
converter: converter,
|
|
|
|
ghCodeBlocks: []
|
|
|
|
},
|
|
|
|
options = showdown.getOptions();
|
2016-12-23 18:07:14 +08:00
|
|
|
|
2017-01-31 13:46:25 +08:00
|
|
|
function runTests () {
|
2017-01-28 10:17:19 +08:00
|
|
|
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 () {
|
2017-01-28 10:17:19 +08:00
|
|
|
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 () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('hashHTMLBlocks')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('anchors', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('anchors')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('autoLinks', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('autoLinks')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
2017-01-28 10:17:19 +08:00
|
|
|
/*
|
2016-12-23 18:07:14 +08:00
|
|
|
.add('blockGamut', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('blockGamut')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
2017-01-28 10:17:19 +08:00
|
|
|
*/
|
2016-12-23 18:07:14 +08:00
|
|
|
.add('blockQuotes', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('blockQuotes')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('codeBlocks', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('codeBlocks')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('codeSpans', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('codeSpans')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('detab', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('detab')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('encodeAmpsAndAngles', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('encodeAmpsAndAngles')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('encodeBackslashEscapes', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('encodeBackslashEscapes')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('encodeCode', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('encodeCode')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('escapeSpecialCharsWithinTagAttributes', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('escapeSpecialCharsWithinTagAttributes')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('githubCodeBlocks', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('githubCodeBlocks')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('hashBlock', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('hashBlock')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('hashElement', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('hashElement')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('hashHTMLSpans', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('hashHTMLSpans')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('hashPreCodeTags', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('hashPreCodeTags')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('headers', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
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 () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('images')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('italicsAndBold', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('italicsAndBold')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('lists', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('lists')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('outdent', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('outdent')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('paragraphs', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('paragraphs')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('spanGamut', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('spanGamut')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('strikethrough', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('strikethrough')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('stripLinkDefinitions', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('stripLinkDefinitions')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('tables', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
showdown.subParser('tables')(testMDFile, options, globals);
|
2016-12-23 18:07:14 +08:00
|
|
|
})
|
|
|
|
.add('unescapeSpecialChars', function () {
|
2017-01-28 10:17:19 +08:00
|
|
|
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
|
|
|
|
};
|