From 2bfa678cab9be337e0c94ae82638fbb997114209 Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Wed, 1 Apr 2015 22:28:15 +0200 Subject: [PATCH] Added separate command for reference benchmark. --- benchmarks.js | 30 +++++++++++++++++++++++++++--- index.js | 4 ---- package.json | 3 ++- test/bootstrap.js | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/benchmarks.js b/benchmarks.js index 345d536..887064c 100644 --- a/benchmarks.js +++ b/benchmarks.js @@ -1,12 +1,36 @@ +var getTestPages = require("./test/bootstrap").getTestPages; + var readability = require("./index.js"); var Readability = readability.Readability; var JSDOMParser = readability.JSDOMParser; -suite("Readability test suite benchmarks", function () { - set("iterations", 100); +var referenceTestPages = [ + "002", + "herald-sun-1", + "lifehacker-working", + "lifehacker-post-comment-load", + "medium-1", + "medium-2", + "salon-1", + "tmz-1", + "wapo-1", + "wapo-2", + "webmd-1", +]; + +var testPages = getTestPages(); + +if (process.env.READABILITY_PERF_REFERENCE === "1") { + testPages = testPages.filter(function(testPage) { + return referenceTestPages.indexOf(testPage.dir) !== -1; + }); +} + +suite("Readability test page perf", function () { + set("iterations", 1); set("type", "static"); - require("./test/bootstrap").getTestPages().forEach(function(testPage) { + testPages.forEach(function(testPage) { bench(testPage.dir + " perf", function() { new JSDOMParser().parse(testPage.source); }); diff --git a/index.js b/index.js index 24367d4..149d760 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,5 @@ var path = require("path"); var fs = require("fs"); -var prettyPrint = require("html").prettyPrint; -var chai = require("chai"); -chai.config.includeStack = true; -var expect = chai.expect; // We want to load Readability and JSDOMParser, which aren't set up as commonjs libraries, // and so we need to do some hocus-pocus with 'vm' to import them on a separate scope diff --git a/package.json b/package.json index 6c186a1..e6ff16f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "test": "mocha test/test-*.js", "generate-testcase": "node test/generate-testcase.js", - "perf": "matcha benchmarks.js" + "perf": "matcha benchmarks.js", + "perf-reference": "READABILITY_PERF_REFERENCE=1 matcha benchmarks.js" }, "repository": { "type": "git", diff --git a/test/bootstrap.js b/test/bootstrap.js index 9e713c6..baa45c1 100644 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -1,5 +1,6 @@ var path = require("path"); var fs = require("fs"); +var prettyPrint = require("html").prettyPrint; function readFile(path) { return fs.readFileSync(path, {encoding: "utf-8"}).trim();