2012-05-02 23:18:10 +00:00
|
|
|
|
2012-05-04 19:23:28 +00:00
|
|
|
var uubench = require('uubench'), // from: https://github.com/moos/uubench
|
|
|
|
fs = require('fs'),
|
|
|
|
_ = require('underscore')._,
|
|
|
|
WordPOS = require('./wordpos'),
|
|
|
|
wordpos = new WordPOS('dict');
|
2012-05-02 23:18:10 +00:00
|
|
|
|
|
|
|
suite = new uubench.Suite({
|
|
|
|
type: 'fixed',
|
|
|
|
iterations: 10,
|
2012-05-04 19:23:28 +00:00
|
|
|
sync: true, // important!
|
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
start: function(tests){
|
|
|
|
console.log('starting %d tests', tests.length);
|
|
|
|
},
|
|
|
|
|
|
|
|
result: function(name, stats){
|
|
|
|
var persec = 1000 / stats.elapsed
|
|
|
|
, ops = .5 + stats.iterations * persec;
|
2012-05-04 19:23:28 +00:00
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
console.log(' \033[90m%s : \033[36m%d \033[90mops/s\033[0m', name, ops | 0, stats);
|
2012-05-04 19:23:28 +00:00
|
|
|
pos && console.log(out(pos));
|
2012-05-02 23:18:10 +00:00
|
|
|
},
|
2012-05-04 19:23:28 +00:00
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
done: function(time){
|
|
|
|
console.log('done in %d msecs', time );
|
|
|
|
},
|
2012-05-04 19:23:28 +00:00
|
|
|
|
2012-05-02 23:18:10 +00:00
|
|
|
section: function(name, stats) {
|
2012-05-04 19:23:28 +00:00
|
|
|
console.log('\033[35m%s\033[0m',name);
|
2012-05-02 23:18:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function out(res){
|
2012-05-04 19:23:28 +00:00
|
|
|
return _(res).keys().map(function(k){ return k + ':' + res[k].length });
|
2012-05-02 23:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-04 19:23:28 +00:00
|
|
|
var text1 = 'laksasdf',
|
|
|
|
text128 = fs.readFileSync('text-128.txt', 'utf8'),
|
|
|
|
text,
|
|
|
|
pos;
|
2012-05-02 23:18:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
function getPOS(next){
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getPOS(text, function(res){
|
|
|
|
pos = res;
|
|
|
|
next();
|
|
|
|
});
|
2012-05-02 23:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getNouns(next){
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getNouns(text, function(res){
|
|
|
|
pos = {nouns: res};
|
|
|
|
next();
|
|
|
|
});
|
2012-05-02 23:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getVerbs(next){
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getVerbs(text, function(res){
|
|
|
|
pos = {verbs: res};
|
|
|
|
next();
|
|
|
|
});
|
2012-05-02 23:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAdjectives(next){
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getAdjectives(text, function(res){
|
|
|
|
pos = {adjectives: res};
|
|
|
|
next();
|
|
|
|
});
|
2012-05-02 23:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAdverbs(next){
|
2012-05-04 19:23:28 +00:00
|
|
|
wordpos.getAdverbs(text, function(res){
|
|
|
|
pos = {adverbs: res};
|
|
|
|
next();
|
|
|
|
});
|
2012-05-02 23:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* one word
|
|
|
|
*/
|
|
|
|
suite.section('--1 word--', function(next){
|
2012-05-04 19:23:28 +00:00
|
|
|
text = text1;
|
|
|
|
next();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
|
|
|
suite.bench('getPOS', getPOS);
|
|
|
|
suite.bench('getNouns', getNouns);
|
|
|
|
suite.bench('getVerbs', getVerbs);
|
|
|
|
suite.bench('getAdjectives', getAdjectives);
|
|
|
|
suite.bench('getAdverbs', getAdverbs);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 128 words
|
|
|
|
*/
|
|
|
|
suite.section('--128 words--', function(next){
|
2012-05-04 19:23:28 +00:00
|
|
|
suite.options.iterations = 1;
|
|
|
|
text = text128;
|
|
|
|
next();
|
2012-05-02 23:18:10 +00:00
|
|
|
});
|
|
|
|
suite.bench('getPOS', getPOS);
|
|
|
|
suite.bench('getNouns', getNouns);
|
|
|
|
suite.bench('getVerbs', getVerbs);
|
|
|
|
suite.bench('getAdjectives', getAdjectives);
|
|
|
|
suite.bench('getAdverbs', getAdverbs);
|
|
|
|
|
|
|
|
|
|
|
|
suite.run();
|