Skip to content

Commit

Permalink
soundex benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 26, 2011
1 parent 88ed70f commit 9780bf4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
32 changes: 32 additions & 0 deletions benchmarks/index.js
@@ -0,0 +1,32 @@

/**
* Module dependencies.
*/

var uubench = require('uubench')
, natural = require('../');

fs = require('fs');
metaphone = natural.Metaphone.process;
soundex = natural.SoundEx.process;

suite = new uubench.Suite({
start: function(){
console.log();
},

result: function(name, stats){
var persec = 1000 / stats.elapsed
, ops = stats.iterations * persec;
console.log(' \033[90m%s : \033[36m%s \033[90mops/s\033[0m', name, ops | 0);
},

done: function(){
console.log();
}
});

require('./metaphone');
require('./soundex');

suite.run();
29 changes: 1 addition & 28 deletions benchmarks.js → benchmarks/metaphone.js
@@ -1,29 +1,4 @@

/**
* Module dependencies.
*/

var uubench = require('uubench')
, natural = require('./')
, metaphone = natural.Metaphone.process
, fs = require('fs');

var suite = new uubench.Suite({
start: function(){
console.log();
},

result: function(name, stats){
var persec = 1000 / stats.elapsed
, ops = stats.iterations * persec;
console.log(' \033[90m%s : \033[36m%s \033[90mops/s\033[0m', name, ops | 0);
},

done: function(){
console.log();
}
});

// single word

suite.bench('metaphone() word', function(next){
Expand All @@ -49,6 +24,4 @@ suite.bench('metaphone() medium', function(next){
metaphone(words2[i]);
}
next();
});

suite.run();
});
27 changes: 27 additions & 0 deletions benchmarks/soundex.js
@@ -0,0 +1,27 @@

// single word

suite.bench('soundex() word', function(next){
soundex('stephen');
next();
});

// small body of text

var words = fs.readFileSync('lib/natural/index.js', 'utf8').split(/\W+/);
suite.bench('soundex() small', function(next){
for (var i = 0, len = words.length; i < len; ++i) {
soundex(words[i]);
}
next();
});

// medium body of text

var words2 = fs.readFileSync('README.md', 'utf8').split(/\W+/);
suite.bench('soundex() medium', function(next){
for (var i = 0, len = words2.length; i < len; ++i) {
soundex(words2[i]);
}
next();
});

0 comments on commit 9780bf4

Please sign in to comment.