performance.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * Created by Tivie on 21/12/2016.
  3. */
  4. 'use strict';
  5. var fs = require('fs'),
  6. showdown = require('../bootstrap').showdown,
  7. converter = new showdown.Converter(),
  8. pkg = require('../../package.json'),
  9. performance = require('../performance/performance.js');
  10. performance.setLibraryName(pkg.name);
  11. performance.setVersion(pkg.version);
  12. performance.setGithubLink('https://github.com/showdownjs/showdown/tree/');
  13. var globals = {
  14. gHtmlBlocks: [],
  15. gHtmlMdBlocks: [],
  16. gHtmlSpans: [],
  17. gUrls: {},
  18. gTitles: {},
  19. gDimensions: {},
  20. gListLevel: 0,
  21. hashLinkCounts: {},
  22. langExtensions: [],
  23. outputModifiers: [],
  24. converter: converter,
  25. ghCodeBlocks: []
  26. },
  27. options = showdown.getOptions();
  28. function runTests() {
  29. var readmeMD = fs.readFileSync('README.md', 'utf8');
  30. new performance.Suite('Basic')
  31. .setOption('cycles', 100)
  32. .add('Simple "Hello World"', function () {
  33. converter.makeHtml('*Hello* **World**!');
  34. })
  35. .add('readme.md', {
  36. prepare: function () {
  37. return readmeMD;
  38. },
  39. test: function (mdText) {
  40. converter.makeHtml(mdText);
  41. }
  42. });
  43. new performance.Suite('subParsers')
  44. .setOption('cycles', 1000)
  45. .add('hashHTMLBlocks', function () {
  46. showdown.subParser('hashHTMLBlocks')(readmeMD, options, globals);
  47. })
  48. .add('anchors', function () {
  49. showdown.subParser('anchors')(readmeMD, options, globals);
  50. })
  51. .add('autoLinks', function () {
  52. showdown.subParser('autoLinks')(readmeMD, options, globals);
  53. })
  54. .add('blockGamut', function () {
  55. showdown.subParser('blockGamut')(readmeMD, options, globals);
  56. })
  57. .add('blockQuotes', function () {
  58. showdown.subParser('blockQuotes')(readmeMD, options, globals);
  59. })
  60. .add('codeBlocks', function () {
  61. showdown.subParser('codeBlocks')(readmeMD, options, globals);
  62. })
  63. .add('codeSpans', function () {
  64. showdown.subParser('codeSpans')(readmeMD, options, globals);
  65. })
  66. .add('detab', function () {
  67. showdown.subParser('detab')(readmeMD, options, globals);
  68. })
  69. .add('encodeAmpsAndAngles', function () {
  70. showdown.subParser('encodeAmpsAndAngles')(readmeMD, options, globals);
  71. })
  72. .add('encodeBackslashEscapes', function () {
  73. showdown.subParser('encodeBackslashEscapes')(readmeMD, options, globals);
  74. })
  75. .add('encodeCode', function () {
  76. showdown.subParser('encodeCode')(readmeMD, options, globals);
  77. })
  78. .add('escapeSpecialCharsWithinTagAttributes', function () {
  79. showdown.subParser('escapeSpecialCharsWithinTagAttributes')(readmeMD, options, globals);
  80. })
  81. .add('githubCodeBlocks', function () {
  82. showdown.subParser('githubCodeBlocks')(readmeMD, options, globals);
  83. })
  84. .add('hashBlock', function () {
  85. showdown.subParser('hashBlock')(readmeMD, options, globals);
  86. })
  87. .add('hashElement', function () {
  88. showdown.subParser('hashElement')(readmeMD, options, globals);
  89. })
  90. .add('hashHTMLSpans', function () {
  91. showdown.subParser('hashHTMLSpans')(readmeMD, options, globals);
  92. })
  93. .add('hashPreCodeTags', function () {
  94. showdown.subParser('hashPreCodeTags')(readmeMD, options, globals);
  95. })
  96. .add('headers', function () {
  97. showdown.subParser('headers')(readmeMD, options, globals);
  98. })
  99. .add('images', function () {
  100. showdown.subParser('images')(readmeMD, options, globals);
  101. })
  102. .add('italicsAndBold', function () {
  103. showdown.subParser('italicsAndBold')(readmeMD, options, globals);
  104. })
  105. .add('lists', function () {
  106. showdown.subParser('lists')(readmeMD, options, globals);
  107. })
  108. .add('outdent', function () {
  109. showdown.subParser('outdent')(readmeMD, options, globals);
  110. })
  111. .add('paragraphs', function () {
  112. showdown.subParser('paragraphs')(readmeMD, options, globals);
  113. })
  114. .add('spanGamut', function () {
  115. showdown.subParser('spanGamut')(readmeMD, options, globals);
  116. })
  117. .add('strikethrough', function () {
  118. showdown.subParser('strikethrough')(readmeMD, options, globals);
  119. })
  120. .add('stripBlankLines', function () {
  121. showdown.subParser('stripBlankLines')(readmeMD, options, globals);
  122. })
  123. .add('stripLinkDefinitions', function () {
  124. showdown.subParser('stripLinkDefinitions')(readmeMD, options, globals);
  125. })
  126. .add('tables', function () {
  127. showdown.subParser('tables')(readmeMD, options, globals);
  128. })
  129. .add('unescapeSpecialChars', function () {
  130. showdown.subParser('unescapeSpecialChars')(readmeMD, options, globals);
  131. });
  132. }
  133. function generateLogs () {
  134. performance.generateLog(null, null, true);
  135. }
  136. module.exports = {
  137. runTests: runTests,
  138. generateLogs: generateLogs
  139. };