Skip to content

Commit

Permalink
[fix] updated the benchmarks to the latest versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Jan 8, 2013
1 parent 12b912c commit d6b549d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"microtime": ""
, "benchmark": ""
, "useragent": "0.1.2"
, "ua-parser": "0.2.3"
, "ua-parser": "0.3.1"
, "useragent_parser": "1.0.0"
, "useragent-parser": "0.1.1"
}
}
41 changes: 25 additions & 16 deletions benchmark/run.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
'use strict';

/**
* Benchmark dependencies
* Benchmark dependencies.
*/

var microtime = require('microtime')
, benchmark = require('benchmark')
, yaml = require('yamlparser')
, path = require('path')
, fs = require('fs');

/**
* Useragent parsers
* Useragent parsers.
*/

var useragent2 = require('../')
, useragent = require('useragent')
, uaparser = require('ua-parser')
, useragent_parser = require('useragent_parser');
, useragent_parser = require('useragent_parser')
, useragent_parser2 = require('useragent-parser');

/**
* Setup the test-files
* Setup the test-files.
*/

var useragentlist = path.join(__dirname, '..', 'tests', 'fixtures', 'testcases.yaml')
, yammy = yaml.eval(fs.readFileSync(useragentlist).toString()).test_cases
, testcases = yammy.map(function (test) { return test.user_agent_string })
, testcases = yammy.map(function (test) {
return test.user_agent_string;
})
, length = testcases.length;

/**
* Setup the benchmark
*/

var froomfroom = new benchmark.Suite;

froomfroom.add('useragent2', function () {
froomfroom
.add('useragent latest', function () {
for (var i = 0; i < length; i++ ) {
useragent2.parse(testcases[i]);
}
Expand All @@ -47,19 +49,26 @@ froomfroom.add('useragent2', function () {
useragent_parser.parse(testcases[i]);
}
})
.add('useragent-parser', function (){
for (var i = 0; i < length; i++ ) {
useragent_parser2.parse(testcases[i]);
}
})
.add('ua-parser', function () {
for (var i = 0; i < length; i++ ) {
uaparser.parse(testcases[i]);
}
})
.on('cycle', function (bench, details) {
.on('cycle', function (event) {
var details = event.target;

console.log('Executed benchmark (%s)', details.name);
console.log('Count (%d), Cycles (%d), Elapsed (%d), Hz (%d)\n'
, details.count
, details.cycles
, details.times.elapsed
, details.hz
);
, details.count
, details.cycles
, details.times.elapsed
, details.hz
);
})
.on('complete', function () {
console.log(this.filter('fastest').pluck('name') + ' has/have the fastest parser');
Expand Down

0 comments on commit d6b549d

Please sign in to comment.