historical/js-xss-for-mayaspace.git/benchmark/vs_validator.js
2024-01-16 11:20:27 -06:00

24 lines
No EOL
547 B
JavaScript

/**
* 性能测试 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 < 200; 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');