Skip to content

Commit

Permalink
Run more perf tests and on larger files
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Aug 29, 2018
1 parent 77630e5 commit 4807865
Show file tree
Hide file tree
Showing 10 changed files with 3,752 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .jshintignore
Expand Up @@ -6,8 +6,7 @@ node_modules/**
python/**
target/**
tools/**
test/resources/underscore-min.js
test/resources/underscore.js
test/resources/*
web/lib/**
build/**

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Expand Up @@ -50,12 +50,16 @@ package: js py build/*.tgz python/dist/*

perf:
@echo ----------------------------------------
@echo Testing beautify performance...
@echo Testing node js beautify performance...
$(NODE) js/test/node-beautify-perf-tests.js || exit 1
@echo Testing node css beautify performance...
$(NODE) js/test/node-beautify-css-perf-tests.js || exit 1
@echo Testing html-beautify performance...
$(NODE) js/test/node-beautify-html-perf-tests.js || exit 1
@echo Testing python beautify performance...
@echo Testing python js beautify performance...
$(SCRIPT_DIR)/python-dev python python/test-perf-jsbeautifier.py || exit 1
@echo Testing python css beautify performance...
$(SCRIPT_DIR)/python-dev python python/test-perf-cssbeautifier.py || exit 1
@echo ----------------------------------------

generate-tests: $(BUILD_DIR)/generate
Expand Down
45 changes: 45 additions & 0 deletions js/test/node-beautify-css-perf-tests.js
@@ -0,0 +1,45 @@
/*global js_beautify: true */
/*jshint node:true */
/*jshint unused:false */

'use strict';

var fs = require('fs'),
SanityTest = require('./sanitytest'),
Benchmark = require('benchmark'),
Urlencoded = require('../lib/unpackers/urlencode_unpacker'),
beautifier = require('../src/index');

function node_beautifier_html_tests() {
console.log('Testing performance...');
var github_css = fs.readFileSync(__dirname + '/../../test/resources/github.css', 'utf8');
var options = {
wrap_line_length: 80
};

//warm-up
beautifier.html(github_css, options);

var suite = new Benchmark.Suite();

suite.add("css-beautify (github.css)", function() {
beautifier.html(github_css, options);
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('error', function(event) {
return 1;
})
.on('complete', function(event) {})
.run();
return 0;
}




if (require.main === module) {
process.exit(node_beautifier_html_tests());
}
6 changes: 5 additions & 1 deletion js/test/node-beautify-html-perf-tests.js
Expand Up @@ -12,14 +12,15 @@ var fs = require('fs'),

function node_beautifier_html_tests() {
console.log('Testing performance...');
var github_html = fs.readFileSync(__dirname + '/../../test/resources/github.html', 'utf8');
var index_html = fs.readFileSync(__dirname + '/../../index.html', 'utf8');
var data_attr = fs.readFileSync(__dirname + '/../../test/resources/html-with-base64image.html', 'utf8');
var options = {
wrap_line_length: 80
};

//warm-up
beautifier.html(index_html, options);
beautifier.html(github_html, options);
beautifier.html(data_attr, options);

var suite = new Benchmark.Suite();
Expand All @@ -30,6 +31,9 @@ function node_beautifier_html_tests() {
.add("html-beautify (base64 image)", function() {
beautifier.html(data_attr, options);
})
.add("html-beautify (github.html)", function() {
beautifier.html(github_html, options);
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
Expand Down
4 changes: 4 additions & 0 deletions js/test/node-beautify-perf-tests.js
Expand Up @@ -14,6 +14,7 @@ function node_beautifier_tests() {
console.log('Testing performance...');
var data = fs.readFileSync(__dirname + '/../../test/resources/underscore.js', 'utf8');
var data_min = fs.readFileSync(__dirname + '/../../test/resources/underscore-min.js', 'utf8');
var github_min = fs.readFileSync(__dirname + '/../../test/resources/github-min.js', 'utf8');
var options = {
wrap_line_length: 80
};
Expand All @@ -30,6 +31,9 @@ function node_beautifier_tests() {
.add("js-beautify (underscore-min)", function() {
beautifier.js(data_min, options);
})
.add("js-beautify (github-min)", function() {
beautifier.js(github_min, options);
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
Expand Down
38 changes: 38 additions & 0 deletions python/test-perf-cssbeautifier.py
@@ -0,0 +1,38 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import copy
import cssbeautifier
options = cssbeautifier.default_options()
options.wrap_line_length = 80
data = ''


def beautifier_test_github_css():
cssbeautifier.beautify(data, options)


def report_perf(fn):
import timeit
iter = 5
time = timeit.timeit(
fn +
"()",
setup="from __main__ import " +
fn +
"; gc.enable()",
number=iter)
print(fn + ": " + str(iter / time) + " cycles/sec")


if __name__ == '__main__':
dirname = os.path.dirname(os.path.abspath(__file__))
github_file = os.path.join(
dirname, "../", "test/resources/github.css")
data = copy.copy(''.join(open(github_file).readlines()))

# warm up
beautifier_test_github_css()

report_perf("beautifier_test_github_css")
10 changes: 9 additions & 1 deletion python/test-perf-jsbeautifier.py
Expand Up @@ -17,10 +17,13 @@ def beautifier_test_underscore():
def beautifier_test_underscore_min():
jsbeautifier.beautify(data_min, options)

def beautifier_test_github_min():
jsbeautifier.beautify(github_min, options)


def report_perf(fn):
import timeit
iter = 50
iter = 5
time = timeit.timeit(
fn +
"()",
Expand All @@ -37,12 +40,17 @@ def report_perf(fn):
dirname, "../", "test/resources/underscore.js")
underscore_min_file = os.path.join(
dirname, "../", "test/resources/underscore-min.js")
github_min_file = os.path.join(
dirname, "../", "test/resources/github-min.js")
data = copy.copy(''.join(open(underscore_file).readlines()))
data_min = copy.copy(''.join(open(underscore_min_file).readlines()))
github_min = copy.copy(''.join(open( github_min_file).readlines()))

# warm up
beautifier_test_underscore()
beautifier_test_underscore_min()
beautifier_test_github_min()

report_perf("beautifier_test_underscore")
report_perf("beautifier_test_underscore_min")
report_perf("beautifier_test_github_min")
3 changes: 3 additions & 0 deletions test/resources/github-min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/resources/github.css

Large diffs are not rendered by default.

0 comments on commit 4807865

Please sign in to comment.