mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-23 04:40:06 +00:00
Run more perf tests and on larger files
This commit is contained in:
parent
77630e5005
commit
4807865f02
@ -6,8 +6,7 @@ node_modules/**
|
|||||||
python/**
|
python/**
|
||||||
target/**
|
target/**
|
||||||
tools/**
|
tools/**
|
||||||
test/resources/underscore-min.js
|
test/resources/*
|
||||||
test/resources/underscore.js
|
|
||||||
web/lib/**
|
web/lib/**
|
||||||
build/**
|
build/**
|
||||||
|
|
||||||
|
8
Makefile
8
Makefile
@ -50,12 +50,16 @@ package: js py build/*.tgz python/dist/*
|
|||||||
|
|
||||||
perf:
|
perf:
|
||||||
@echo ----------------------------------------
|
@echo ----------------------------------------
|
||||||
@echo Testing beautify performance...
|
@echo Testing node js beautify performance...
|
||||||
$(NODE) js/test/node-beautify-perf-tests.js || exit 1
|
$(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...
|
@echo Testing html-beautify performance...
|
||||||
$(NODE) js/test/node-beautify-html-perf-tests.js || exit 1
|
$(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
|
$(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 ----------------------------------------
|
@echo ----------------------------------------
|
||||||
|
|
||||||
generate-tests: $(BUILD_DIR)/generate
|
generate-tests: $(BUILD_DIR)/generate
|
||||||
|
45
js/test/node-beautify-css-perf-tests.js
Normal file
45
js/test/node-beautify-css-perf-tests.js
Normal file
@ -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());
|
||||||
|
}
|
@ -12,6 +12,7 @@ var fs = require('fs'),
|
|||||||
|
|
||||||
function node_beautifier_html_tests() {
|
function node_beautifier_html_tests() {
|
||||||
console.log('Testing performance...');
|
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 index_html = fs.readFileSync(__dirname + '/../../index.html', 'utf8');
|
||||||
var data_attr = fs.readFileSync(__dirname + '/../../test/resources/html-with-base64image.html', 'utf8');
|
var data_attr = fs.readFileSync(__dirname + '/../../test/resources/html-with-base64image.html', 'utf8');
|
||||||
var options = {
|
var options = {
|
||||||
@ -19,7 +20,7 @@ function node_beautifier_html_tests() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//warm-up
|
//warm-up
|
||||||
beautifier.html(index_html, options);
|
beautifier.html(github_html, options);
|
||||||
beautifier.html(data_attr, options);
|
beautifier.html(data_attr, options);
|
||||||
|
|
||||||
var suite = new Benchmark.Suite();
|
var suite = new Benchmark.Suite();
|
||||||
@ -30,6 +31,9 @@ function node_beautifier_html_tests() {
|
|||||||
.add("html-beautify (base64 image)", function() {
|
.add("html-beautify (base64 image)", function() {
|
||||||
beautifier.html(data_attr, options);
|
beautifier.html(data_attr, options);
|
||||||
})
|
})
|
||||||
|
.add("html-beautify (github.html)", function() {
|
||||||
|
beautifier.html(github_html, options);
|
||||||
|
})
|
||||||
// add listeners
|
// add listeners
|
||||||
.on('cycle', function(event) {
|
.on('cycle', function(event) {
|
||||||
console.log(String(event.target));
|
console.log(String(event.target));
|
||||||
|
@ -14,6 +14,7 @@ function node_beautifier_tests() {
|
|||||||
console.log('Testing performance...');
|
console.log('Testing performance...');
|
||||||
var data = fs.readFileSync(__dirname + '/../../test/resources/underscore.js', 'utf8');
|
var data = fs.readFileSync(__dirname + '/../../test/resources/underscore.js', 'utf8');
|
||||||
var data_min = fs.readFileSync(__dirname + '/../../test/resources/underscore-min.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 = {
|
var options = {
|
||||||
wrap_line_length: 80
|
wrap_line_length: 80
|
||||||
};
|
};
|
||||||
@ -30,6 +31,9 @@ function node_beautifier_tests() {
|
|||||||
.add("js-beautify (underscore-min)", function() {
|
.add("js-beautify (underscore-min)", function() {
|
||||||
beautifier.js(data_min, options);
|
beautifier.js(data_min, options);
|
||||||
})
|
})
|
||||||
|
.add("js-beautify (github-min)", function() {
|
||||||
|
beautifier.js(github_min, options);
|
||||||
|
})
|
||||||
// add listeners
|
// add listeners
|
||||||
.on('cycle', function(event) {
|
.on('cycle', function(event) {
|
||||||
console.log(String(event.target));
|
console.log(String(event.target));
|
||||||
|
38
python/test-perf-cssbeautifier.py
Executable file
38
python/test-perf-cssbeautifier.py
Executable file
@ -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")
|
@ -17,10 +17,13 @@ def beautifier_test_underscore():
|
|||||||
def beautifier_test_underscore_min():
|
def beautifier_test_underscore_min():
|
||||||
jsbeautifier.beautify(data_min, options)
|
jsbeautifier.beautify(data_min, options)
|
||||||
|
|
||||||
|
def beautifier_test_github_min():
|
||||||
|
jsbeautifier.beautify(github_min, options)
|
||||||
|
|
||||||
|
|
||||||
def report_perf(fn):
|
def report_perf(fn):
|
||||||
import timeit
|
import timeit
|
||||||
iter = 50
|
iter = 5
|
||||||
time = timeit.timeit(
|
time = timeit.timeit(
|
||||||
fn +
|
fn +
|
||||||
"()",
|
"()",
|
||||||
@ -37,12 +40,17 @@ if __name__ == '__main__':
|
|||||||
dirname, "../", "test/resources/underscore.js")
|
dirname, "../", "test/resources/underscore.js")
|
||||||
underscore_min_file = os.path.join(
|
underscore_min_file = os.path.join(
|
||||||
dirname, "../", "test/resources/underscore-min.js")
|
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 = copy.copy(''.join(open(underscore_file).readlines()))
|
||||||
data_min = copy.copy(''.join(open(underscore_min_file).readlines()))
|
data_min = copy.copy(''.join(open(underscore_min_file).readlines()))
|
||||||
|
github_min = copy.copy(''.join(open( github_min_file).readlines()))
|
||||||
|
|
||||||
# warm up
|
# warm up
|
||||||
beautifier_test_underscore()
|
beautifier_test_underscore()
|
||||||
beautifier_test_underscore_min()
|
beautifier_test_underscore_min()
|
||||||
|
beautifier_test_github_min()
|
||||||
|
|
||||||
report_perf("beautifier_test_underscore")
|
report_perf("beautifier_test_underscore")
|
||||||
report_perf("beautifier_test_underscore_min")
|
report_perf("beautifier_test_underscore_min")
|
||||||
|
report_perf("beautifier_test_github_min")
|
||||||
|
3
test/resources/github-min.js
vendored
Normal file
3
test/resources/github-min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
test/resources/github.css
Normal file
7
test/resources/github.css
Normal file
File diff suppressed because one or more lines are too long
3634
test/resources/github.html
Normal file
3634
test/resources/github.html
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user