From bba9722ad4720794ddf0fedfda0663b258638b48 Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Fri, 23 Dec 2016 10:07:14 +0000 Subject: [PATCH] test: add more performance tests --- performance.json | 2 +- performance.log.md | 49 ++++++++++- test/node/performance.js | 147 +++++++++++++++++++++++++++----- test/performance/performance.js | 18 +++- 4 files changed, 190 insertions(+), 26 deletions(-) diff --git a/performance.json b/performance.json index 22a818a..16af980 100644 --- a/performance.json +++ b/performance.json @@ -1 +1 @@ -{"1.5.4":[{"suiteName":"Basic","cycles":100,"tests":[{"name":"Simple \"Hello World\"","time":0.30990324000000025,"maxTime":5.549075,"minTime":0.14916800000000308},{"name":"readme.md","time":8.072704459999997,"maxTime":17.975579000000003,"minTime":7.220064999999977}]}]} \ No newline at end of file +{"1.5.5":[{"suiteName":"Basic","cycles":100,"tests":[{"name":"Simple \"Hello World\"","time":0.31472779000000006,"maxTime":5.7157219999999995,"minTime":0.1630309999999966},{"name":"readme.md","time":8.35187898,"maxTime":18.016863999999998,"minTime":7.207408999999984}]},{"suiteName":"subParsers","cycles":1000,"tests":[{"name":"hashHTMLBlocks","time":0.673032811000001,"maxTime":1.1442289999999957,"minTime":0.6216859999999542},{"name":"anchors","time":0.17780483999999888,"maxTime":0.5279669999999896,"minTime":0.15700300000003153},{"name":"autoLinks","time":0.014361767000001236,"maxTime":0.19256300000006377,"minTime":0.012655999999878986},{"name":"blockGamut","time":7.3270934659999964,"maxTime":16.04994700000134,"minTime":6.464278000000377},{"name":"blockQuotes","time":0.06438723300000856,"maxTime":0.2558470000003581,"minTime":0.05816000000049826},{"name":"codeBlocks","time":0.07155547099998148,"maxTime":1.5896259999990434,"minTime":0.05936599999949976},{"name":"codeSpans","time":0.1839475929999935,"maxTime":1.4350329999997484,"minTime":0.16453699999874516},{"name":"detab","time":0.024342816999995194,"maxTime":0.19678200000089419,"minTime":0.02199799999834795},{"name":"encodeAmpsAndAngles","time":0.016193075999983195,"maxTime":0.35378599999967264,"minTime":0.013559999999415595},{"name":"encodeBackslashEscapes","time":0.01439162099999885,"maxTime":0.23565699999926437,"minTime":0.012354999998933636},{"name":"encodeCode","time":0.16650568799998655,"maxTime":0.48909199999980046,"minTime":0.1485659999998461},{"name":"encodeEmailAddress","time":2.2962369480000233,"maxTime":3.975118999998813,"minTime":2.079321000001073},{"name":"escapeSpecialCharsWithinTagAttributes","time":0.06015714999998454,"maxTime":0.41375499999958265,"minTime":0.05303699999967648},{"name":"githubCodeBlocks","time":0.07636622499999976,"maxTime":4.3967090000005555,"minTime":0.05514699999912409},{"name":"hashBlock","time":0.023663276999977823,"maxTime":5.066611999998713,"minTime":0.010847999999896274},{"name":"hashElement","time":0.0007292739999957121,"maxTime":0.23927300000104879,"minTime":0},{"name":"hashHTMLSpans","time":0.031071996999991826,"maxTime":3.5767329999998765,"minTime":0.010245999999824562},{"name":"hashPreCodeTags","time":0.018975442000006296,"maxTime":0.3323899999995774,"minTime":0.014765999998417101},{"name":"headers","time":0.45554695500000525,"maxTime":2.677201000000423,"minTime":0.3911530000004859},{"name":"images","time":0.04111330700001417,"maxTime":1.6565260000006674,"minTime":0.0322439999999915},{"name":"italicsAndBold","time":0.038311039999998686,"maxTime":0.2980360000001383,"minTime":0.03465499999947497},{"name":"lists","time":5.024616153999989,"maxTime":9.631475000000137,"minTime":4.572998999999982},{"name":"outdent","time":0.0506727579999897,"maxTime":0.5855249999985972,"minTime":0.04369599999699858},{"name":"paragraphs","time":1.3435436269999992,"maxTime":2.651585999999952,"minTime":1.1951570000019274},{"name":"spanGamut","time":0.6120240349999804,"maxTime":1.057440000000497,"minTime":0.5553889999973762},{"name":"strikethrough","time":0.00045323800000551275,"maxTime":0.22752000000036787,"minTime":0},{"name":"stripBlankLines","time":0.03007630300002711,"maxTime":0.29351499999756925,"minTime":0.02681999999913387},{"name":"stripLinkDefinitions","time":0.06855551200000627,"maxTime":0.4496159999980591,"minTime":0.06026999999812688},{"name":"tables","time":0.0008534279999839782,"maxTime":0.2046169999994163,"minTime":0},{"name":"unescapeSpecialChars","time":0.0035457099999912315,"maxTime":0.1681540000026871,"minTime":0.0027119999977003317}]}],"1.5.4":[{"suiteName":"Basic","cycles":100,"tests":[{"name":"Simple \"Hello World\"","time":0.30990324000000025,"maxTime":5.549075,"minTime":0.14916800000000308},{"name":"readme.md","time":8.072704459999997,"maxTime":17.975579000000003,"minTime":7.220064999999977}]}]} \ No newline at end of file diff --git a/performance.log.md b/performance.log.md index b68d264..5f3bea1 100644 --- a/performance.log.md +++ b/performance.log.md @@ -1,10 +1,55 @@ # Performance Tests for showdown +## [version 1.5.5](https://github.com/showdownjs/showdown/tree/) + +### Test Suite: Basic (100 cycles) +| test | avgTime | max | min | +|:-----|--------:|----:|----:| +|Simple "Hello World"|0.315|5.716|0.163| +|readme.md|8.352|18.017|7.207| + +### Test Suite: subParsers (1000 cycles) +| test | avgTime | max | min | +|:-----|--------:|----:|----:| +|hashHTMLBlocks|0.673|1.144|0.622| +|anchors|0.178|0.528|0.157| +|autoLinks|0.014|0.193|0.013| +|blockGamut|7.327|16.050|6.464| +|blockQuotes|0.064|0.256|0.058| +|codeBlocks|0.072|1.590|0.059| +|codeSpans|0.184|1.435|0.165| +|detab|0.024|0.197|0.022| +|encodeAmpsAndAngles|0.016|0.354|0.014| +|encodeBackslashEscapes|0.014|0.236|0.012| +|encodeCode|0.167|0.489|0.149| +|encodeEmailAddress|2.296|3.975|2.079| +|escapeSpecialCharsWithinTagAttributes|0.060|0.414|0.053| +|githubCodeBlocks|0.076|4.397|0.055| +|hashBlock|0.024|5.067|0.011| +|hashElement|0.001|0.239|0.000| +|hashHTMLSpans|0.031|3.577|0.010| +|hashPreCodeTags|0.019|0.332|0.015| +|headers|0.456|2.677|0.391| +|images|0.041|1.657|0.032| +|italicsAndBold|0.038|0.298|0.035| +|lists|5.025|9.631|4.573| +|outdent|0.051|0.586|0.044| +|paragraphs|1.344|2.652|1.195| +|spanGamut|0.612|1.057|0.555| +|strikethrough|0.000|0.228|0.000| +|stripBlankLines|0.030|0.294|0.027| +|stripLinkDefinitions|0.069|0.450|0.060| +|tables|0.001|0.205|0.000| +|unescapeSpecialChars|0.004|0.168|0.003| + + ## [version 1.5.4](https://github.com/showdownjs/showdown/tree/) ### Test Suite: Basic (100 cycles) - - **Simple "Hello World":** took 0.310ms (*max: 5.549ms; min: 0.149ms*) - - **readme.md:** took 8.073ms (*max: 17.976ms; min: 7.220ms*) +| test | avgTime | max | min | +|:-----|--------:|----:|----:| +|Simple "Hello World"|0.310|5.549|0.149| +|readme.md|8.073|17.976|7.220| diff --git a/test/node/performance.js b/test/node/performance.js index d3c25c9..e41d3b4 100644 --- a/test/node/performance.js +++ b/test/node/performance.js @@ -12,25 +12,134 @@ performance.setLibraryName(pkg.name); performance.setVersion(pkg.version); performance.setGithubLink('https://github.com/showdownjs/showdown/tree/'); -var - runTests = function () { - new performance.Suite('Basic') - .setOption('cycles', 100) - .add('Simple "Hello World"', function () { - converter.makeHtml('*Hello* **World**!'); - }) - .add('readme.md', { - prepare: function () { - return fs.readFileSync('README.md', 'utf8'); - }, - test: function (mdText) { - converter.makeHtml(mdText); - } - }); - }, - generateLogs = function () { - performance.generateLog(); - }; +var globals = { + gHtmlBlocks: [], + gHtmlMdBlocks: [], + gHtmlSpans: [], + gUrls: {}, + gTitles: {}, + gDimensions: {}, + gListLevel: 0, + hashLinkCounts: {}, + langExtensions: [], + outputModifiers: [], + converter: converter, + ghCodeBlocks: [] +}, + options = showdown.getOptions(); + +function runTests() { + var readmeMD = fs.readFileSync('README.md', 'utf8'); + new performance.Suite('Basic') + .setOption('cycles', 100) + .add('Simple "Hello World"', function () { + converter.makeHtml('*Hello* **World**!'); + }) + .add('readme.md', { + prepare: function () { + return readmeMD; + }, + test: function (mdText) { + converter.makeHtml(mdText); + } + }); + new performance.Suite('subParsers') + .setOption('cycles', 1000) + .add('hashHTMLBlocks', function () { + showdown.subParser('hashHTMLBlocks')(readmeMD, options, globals); + }) + .add('anchors', function () { + showdown.subParser('anchors')(readmeMD, options, globals); + }) + .add('autoLinks', function () { + showdown.subParser('autoLinks')(readmeMD, options, globals); + }) + .add('blockGamut', function () { + showdown.subParser('blockGamut')(readmeMD, options, globals); + }) + .add('blockQuotes', function () { + showdown.subParser('blockQuotes')(readmeMD, options, globals); + }) + .add('codeBlocks', function () { + showdown.subParser('codeBlocks')(readmeMD, options, globals); + }) + .add('codeSpans', function () { + showdown.subParser('codeSpans')(readmeMD, options, globals); + }) + .add('detab', function () { + showdown.subParser('detab')(readmeMD, options, globals); + }) + .add('encodeAmpsAndAngles', function () { + showdown.subParser('encodeAmpsAndAngles')(readmeMD, options, globals); + }) + .add('encodeBackslashEscapes', function () { + showdown.subParser('encodeBackslashEscapes')(readmeMD, options, globals); + }) + .add('encodeCode', function () { + showdown.subParser('encodeCode')(readmeMD, options, globals); + }) + .add('encodeEmailAddress', function () { + showdown.subParser('encodeEmailAddress')(readmeMD, options, globals); + }) + .add('escapeSpecialCharsWithinTagAttributes', function () { + showdown.subParser('escapeSpecialCharsWithinTagAttributes')(readmeMD, options, globals); + }) + .add('githubCodeBlocks', function () { + showdown.subParser('githubCodeBlocks')(readmeMD, options, globals); + }) + .add('hashBlock', function () { + showdown.subParser('hashBlock')(readmeMD, options, globals); + }) + .add('hashElement', function () { + showdown.subParser('hashElement')(readmeMD, options, globals); + }) + .add('hashHTMLSpans', function () { + showdown.subParser('hashHTMLSpans')(readmeMD, options, globals); + }) + .add('hashPreCodeTags', function () { + showdown.subParser('hashPreCodeTags')(readmeMD, options, globals); + }) + .add('headers', function () { + showdown.subParser('headers')(readmeMD, options, globals); + }) + .add('images', function () { + showdown.subParser('images')(readmeMD, options, globals); + }) + .add('italicsAndBold', function () { + showdown.subParser('italicsAndBold')(readmeMD, options, globals); + }) + .add('lists', function () { + showdown.subParser('lists')(readmeMD, options, globals); + }) + .add('outdent', function () { + showdown.subParser('outdent')(readmeMD, options, globals); + }) + .add('paragraphs', function () { + showdown.subParser('paragraphs')(readmeMD, options, globals); + }) + .add('spanGamut', function () { + showdown.subParser('spanGamut')(readmeMD, options, globals); + }) + .add('strikethrough', function () { + showdown.subParser('strikethrough')(readmeMD, options, globals); + }) + .add('stripBlankLines', function () { + showdown.subParser('stripBlankLines')(readmeMD, options, globals); + }) + .add('stripLinkDefinitions', function () { + showdown.subParser('stripLinkDefinitions')(readmeMD, options, globals); + }) + .add('tables', function () { + showdown.subParser('tables')(readmeMD, options, globals); + }) + .add('unescapeSpecialChars', function () { + showdown.subParser('unescapeSpecialChars')(readmeMD, options, globals); + }); +} + +function generateLogs () { + performance.generateLog(null, null, true); +} module.exports = { runTests: runTests, diff --git a/test/performance/performance.js b/test/performance/performance.js index 6e81c18..a18b72d 100644 --- a/test/performance/performance.js +++ b/test/performance/performance.js @@ -27,9 +27,10 @@ performance.setGithubLink = function (url) { performance.githubLink = url; }; -performance.generateLog = function (filename, MDFilename) { +performance.generateLog = function (filename, MDFilename, asTable) { filename = filename || performance.logFile; MDFilename = MDFilename || performance.MDFile; + asTable = !!asTable; fs.closeSync(fs.openSync(filename, 'a')); @@ -95,11 +96,12 @@ performance.generateLog = function (filename, MDFilename) { fs.writeFileSync(filename, JSON.stringify(finalJsonObj)); - generateMD(MDFilename, finalJsonObj); + generateMD(MDFilename, finalJsonObj, asTable); }; -function generateMD(filename, obj) { +function generateMD(filename, obj, asTable) { fs.closeSync(fs.openSync(filename, 'w')); + asTable = !!asTable; // generate MD var otp = '# Performance Tests for ' + performance.libraryName + '\n\n\n'; @@ -111,11 +113,19 @@ function generateMD(filename, obj) { for (var i = 0; i < testSuite.length; ++i) { otp += '### Test Suite: ' + testSuite[i].suiteName + ' (' + testSuite[i].cycles + ' cycles)\n'; var tests = testSuite[i].tests; + if (asTable) { + otp += '| test | avgTime | max | min |\n'; + otp += '|:-----|--------:|----:|----:|\n'; + } for (var ii = 0; ii < tests.length; ++ii) { var time = parseFloat(tests[ii].time).toFixed(3), maxTime = parseFloat(tests[ii].maxTime).toFixed(3), minTime = parseFloat(tests[ii].minTime).toFixed(3); - otp += ' - **' + tests[ii].name + ':** took ' + time + 'ms (*max: ' + maxTime + 'ms; min: ' + minTime + 'ms*)\n'; + if (asTable) { + otp += '|' + tests[ii].name + '|' + time + '|' + maxTime + '|' + minTime + '|\n'; + } else { + otp += ' - **' + tests[ii].name + ':** took ' + time + 'ms (*max: ' + maxTime + 'ms; min: ' + minTime + 'ms*)\n'; + } } otp += '\n'; }