Skip to content

Commit 4807865

Browse files
committed
Run more perf tests and on larger files
1 parent 77630e5 commit 4807865

10 files changed

+3752
-6
lines changed

.jshintignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ node_modules/**
66
python/**
77
target/**
88
tools/**
9-
test/resources/underscore-min.js
10-
test/resources/underscore.js
9+
test/resources/*
1110
web/lib/**
1211
build/**
1312

Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ package: js py build/*.tgz python/dist/*
5050

5151
perf:
5252
@echo ----------------------------------------
53-
@echo Testing beautify performance...
53+
@echo Testing node js beautify performance...
5454
$(NODE) js/test/node-beautify-perf-tests.js || exit 1
55+
@echo Testing node css beautify performance...
56+
$(NODE) js/test/node-beautify-css-perf-tests.js || exit 1
5557
@echo Testing html-beautify performance...
5658
$(NODE) js/test/node-beautify-html-perf-tests.js || exit 1
57-
@echo Testing python beautify performance...
59+
@echo Testing python js beautify performance...
5860
$(SCRIPT_DIR)/python-dev python python/test-perf-jsbeautifier.py || exit 1
61+
@echo Testing python css beautify performance...
62+
$(SCRIPT_DIR)/python-dev python python/test-perf-cssbeautifier.py || exit 1
5963
@echo ----------------------------------------
6064

6165
generate-tests: $(BUILD_DIR)/generate
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*global js_beautify: true */
2+
/*jshint node:true */
3+
/*jshint unused:false */
4+
5+
'use strict';
6+
7+
var fs = require('fs'),
8+
SanityTest = require('./sanitytest'),
9+
Benchmark = require('benchmark'),
10+
Urlencoded = require('../lib/unpackers/urlencode_unpacker'),
11+
beautifier = require('../src/index');
12+
13+
function node_beautifier_html_tests() {
14+
console.log('Testing performance...');
15+
var github_css = fs.readFileSync(__dirname + '/../../test/resources/github.css', 'utf8');
16+
var options = {
17+
wrap_line_length: 80
18+
};
19+
20+
//warm-up
21+
beautifier.html(github_css, options);
22+
23+
var suite = new Benchmark.Suite();
24+
25+
suite.add("css-beautify (github.css)", function() {
26+
beautifier.html(github_css, options);
27+
})
28+
// add listeners
29+
.on('cycle', function(event) {
30+
console.log(String(event.target));
31+
})
32+
.on('error', function(event) {
33+
return 1;
34+
})
35+
.on('complete', function(event) {})
36+
.run();
37+
return 0;
38+
}
39+
40+
41+
42+
43+
if (require.main === module) {
44+
process.exit(node_beautifier_html_tests());
45+
}

js/test/node-beautify-html-perf-tests.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ var fs = require('fs'),
1212

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

2122
//warm-up
22-
beautifier.html(index_html, options);
23+
beautifier.html(github_html, options);
2324
beautifier.html(data_attr, options);
2425

2526
var suite = new Benchmark.Suite();
@@ -30,6 +31,9 @@ function node_beautifier_html_tests() {
3031
.add("html-beautify (base64 image)", function() {
3132
beautifier.html(data_attr, options);
3233
})
34+
.add("html-beautify (github.html)", function() {
35+
beautifier.html(github_html, options);
36+
})
3337
// add listeners
3438
.on('cycle', function(event) {
3539
console.log(String(event.target));

js/test/node-beautify-perf-tests.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function node_beautifier_tests() {
1414
console.log('Testing performance...');
1515
var data = fs.readFileSync(__dirname + '/../../test/resources/underscore.js', 'utf8');
1616
var data_min = fs.readFileSync(__dirname + '/../../test/resources/underscore-min.js', 'utf8');
17+
var github_min = fs.readFileSync(__dirname + '/../../test/resources/github-min.js', 'utf8');
1718
var options = {
1819
wrap_line_length: 80
1920
};
@@ -30,6 +31,9 @@ function node_beautifier_tests() {
3031
.add("js-beautify (underscore-min)", function() {
3132
beautifier.js(data_min, options);
3233
})
34+
.add("js-beautify (github-min)", function() {
35+
beautifier.js(github_min, options);
36+
})
3337
// add listeners
3438
.on('cycle', function(event) {
3539
console.log(String(event.target));

python/test-perf-cssbeautifier.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
import copy
6+
import cssbeautifier
7+
options = cssbeautifier.default_options()
8+
options.wrap_line_length = 80
9+
data = ''
10+
11+
12+
def beautifier_test_github_css():
13+
cssbeautifier.beautify(data, options)
14+
15+
16+
def report_perf(fn):
17+
import timeit
18+
iter = 5
19+
time = timeit.timeit(
20+
fn +
21+
"()",
22+
setup="from __main__ import " +
23+
fn +
24+
"; gc.enable()",
25+
number=iter)
26+
print(fn + ": " + str(iter / time) + " cycles/sec")
27+
28+
29+
if __name__ == '__main__':
30+
dirname = os.path.dirname(os.path.abspath(__file__))
31+
github_file = os.path.join(
32+
dirname, "../", "test/resources/github.css")
33+
data = copy.copy(''.join(open(github_file).readlines()))
34+
35+
# warm up
36+
beautifier_test_github_css()
37+
38+
report_perf("beautifier_test_github_css")

python/test-perf-jsbeautifier.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ def beautifier_test_underscore():
1717
def beautifier_test_underscore_min():
1818
jsbeautifier.beautify(data_min, options)
1919

20+
def beautifier_test_github_min():
21+
jsbeautifier.beautify(github_min, options)
22+
2023

2124
def report_perf(fn):
2225
import timeit
23-
iter = 50
26+
iter = 5
2427
time = timeit.timeit(
2528
fn +
2629
"()",
@@ -37,12 +40,17 @@ def report_perf(fn):
3740
dirname, "../", "test/resources/underscore.js")
3841
underscore_min_file = os.path.join(
3942
dirname, "../", "test/resources/underscore-min.js")
43+
github_min_file = os.path.join(
44+
dirname, "../", "test/resources/github-min.js")
4045
data = copy.copy(''.join(open(underscore_file).readlines()))
4146
data_min = copy.copy(''.join(open(underscore_min_file).readlines()))
47+
github_min = copy.copy(''.join(open( github_min_file).readlines()))
4248

4349
# warm up
4450
beautifier_test_underscore()
4551
beautifier_test_underscore_min()
52+
beautifier_test_github_min()
4653

4754
report_perf("beautifier_test_underscore")
4855
report_perf("beautifier_test_underscore_min")
56+
report_perf("beautifier_test_github_min")

test/resources/github-min.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/resources/github.css

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)