From 055039146d6f30d298b2f8d4c15db2bc3495c318 Mon Sep 17 00:00:00 2001 From: Jayson Harshbarger Date: Mon, 16 May 2016 18:24:39 +0900 Subject: [PATCH] Added Markdown Reporter --- lib/matcha/reporters/markdown.js | 70 ++++++++++++++++++++++++++++++++ package.json | 7 +++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 lib/matcha/reporters/markdown.js diff --git a/lib/matcha/reporters/markdown.js b/lib/matcha/reporters/markdown.js new file mode 100644 index 0000000..6147bd5 --- /dev/null +++ b/lib/matcha/reporters/markdown.js @@ -0,0 +1,70 @@ +/*! + * Matcha - Markdown Reporter + * Created by J. Harshbarger, based on + * Matcha - Plain Reporter + * Copyright(c) 2013 Lauris Vavere + * MIT Licensed + */ + +/*! + * Internal Dependancies + */ + var platform = require('platform'); + + +function pad(str, width) { + str = str.substr(0,width-3); + return str + ' ' + Array(width - str.length-2).join('.') + ' '; +}; + + + +/** + * Plain + * + * The markdown text matcha reporter. + * + * @param {Runner} runner + * @api public + */ + +function desc(a,b) { + return b.stats.ops - a.stats.ops; +} + +module.exports = function(runner, utils) { + var humanize = utils.humanize; + + runner.on('start', function () { + console.log('# ' + platform.description); + }); + + runner.on('end', function (stats) { + console.log(''); + /* console.log('Suites: ' + stats.suites); + console.log('Benches: ' + stats.benches); + console.log('Elapsed: ' + humanize(stats.elapsed.toFixed(2)) + ' ms'); */ + }); + + runner.on('suite start', function (suite) { + console.log(''); + console.log('## ' + suite.title); + console.log(''); + }); + + runner.on('suite end', function (suite) { + if (suite.benches.length > 1) { + var benches = suite.benches.slice().sort(desc); + console.log(''); + console.log('*Fastest is **' + benches[0].title + '***'); + } + }); + + runner.on('bench start', function (bench) { + // process.stdout.write(' ' + pad(bench.title, 50)); + }); + + runner.on('bench end', function (results) { + console.log(' ' + pad(results.title, 50) + humanize(results.ops.toFixed(0)) + ' op/s'); + }); +}; diff --git a/package.json b/package.json index e0bb5f7..6caf7c7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,11 @@ "author": "Jake Luer ", "name": "matcha", "description": "Benchmark your code.", - "keyword": [ "benchmark", "bench", "performance" ], + "keyword": [ + "benchmark", + "bench", + "performance" + ], "version": "0.7.0", "repository": { "type": "git", @@ -19,6 +23,7 @@ }, "dependencies": { "electron": "0.4.x", + "platform": "^1.3.1", "v8-argv": "0.1.x" }, "devDependencies": {}