性能测试程序

This commit is contained in:
leizongmin
2012-09-19 11:33:14 +08:00
parent a25c73c8eb
commit 40a01555d4
5 changed files with 1529 additions and 1 deletions

2
.gitignore vendored
View File

@@ -13,3 +13,5 @@ results
node_modules
npm-debug.log
benchmark/result*.html

View File

@@ -35,6 +35,13 @@ console.log(xss('<a href="javascript:ooxx">abc</a>', function (tag, attr, value)
**npm test**
## 性能
解析速度为**6.26MB/s**,而另外一个**validator**模块的xss()函数速度仅为**2.82MB/s**。
测试代码参考**benchmark**目录
## 授权协议
基于MIT协议发布

1471
benchmark/file.html Normal file

File diff suppressed because it is too large Load Diff

24
benchmark/index.js Normal file
View File

@@ -0,0 +1,24 @@
/**
* 性能测试
*/
var xss = require('../');
var fs = require('fs');
var html = fs.readFileSync(__dirname + '/file.html', 'utf8');
var timeStart = Date.now();
for (var i = 0; i < 1000; i++) {
var ret = xss(html);
}
var timeEnd = Date.now();
//console.log(ret);
fs.writeFileSync(__dirname + '/result.html', ret);
var spent = timeEnd - timeStart;
var speed = (((html.length * i) / spent * 1000) / 1024 / 1024).toFixed(2);
console.log('spent ' + spent + 'ms, ' + speed + 'MB/s');

24
benchmark/vs_validator.js Normal file
View File

@@ -0,0 +1,24 @@
/**
* 性能测试 validator模块
*/
var sanitize = require('validator').sanitize;
var fs = require('fs');
var html = fs.readFileSync(__dirname + '/file.html', 'utf8');
var timeStart = Date.now();
for (var i = 0; i < 1000; i++) {
var ret = sanitize(html).xss();
}
var timeEnd = Date.now();
//console.log(ret);
fs.writeFileSync(__dirname + '/result_validator.html', ret);
var spent = timeEnd - timeStart;
var speed = (((html.length * i) / spent * 1000) / 1024 / 1024).toFixed(2);
console.log('spent ' + spent + 'ms, ' + speed + 'MB/s');