Ver código fonte

test: add more performance tests

Estevao Soares dos Santos 8 anos atrás
pai
commit
bba9722ad4
4 arquivos alterados com 189 adições e 26 exclusões
  1. 0 1
      performance.json
  2. 47 2
      performance.log.md
  3. 128 19
      test/node/performance.js
  4. 14 4
      test/performance/performance.js

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 1
performance.json


+ 47 - 2
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|
 
 

+ 128 - 19
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,

+ 14 - 4
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';
       }

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff