Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Inital benchmark

  • Loading branch information...
commit 7540444c146b545306ea6d3dfa0475d660157755 1 parent 8b98665
@3rd-Eden authored
Showing with 77 additions and 0 deletions.
  1. +11 −0 benchmark/package.json
  2. +66 −0 benchmark/run.js
View
11 benchmark/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "ua-benchmarker"
+ , "description": "benchmarks the different user agent parsers to see their parse performance"
+ , "version": "0.0.0"
+ , "dependencies": {
+ "microtime": ""
+ , "benchmark": ""
+ , "useragent": "0.1.2"
+ , "ua-parser": "0.2.3"
+ }
+}
View
66 benchmark/run.js
@@ -0,0 +1,66 @@
+/**
+ * Benchmark dependencies
+ */
+
+var microtime = require('microtime')
+ , benchmark = require('benchmark')
+ , yaml = require('yamlparser')
+ , path = require('path')
+ , fs = require('fs');
+
+/**
+ * Useragent parsers
+ */
+
+var useragent2 = require('../')
+ , useragent = require('useragent')
+ , uaparser = require('ua-parser');
+
+/**
+ * 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 })
+ , length = testcases.length;
+
+/**
+ * Setup the benchmark
+ */
+
+var froomfroom = new benchmark.Suite;
+
+froomfroom.add('useragent2', function () {
+ for (var i = 0; i < length; i++ ) {
+ useragent2.parse(testcases[i]);
+ }
+})
+.add('useragent1', function () {
+ for (var i = 0; i < length; i++ ) {
+ useragent.parser(testcases[i]);
+ }
+})
+.add('ua-parser', function () {
+ for (var i = 0; i < length; i++ ) {
+ uaparser.parse(testcases[i]);
+ }
+})
+.on('cycle', function (bench, details) {
+ 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
+ );
+})
+.on('complete', function () {
+ console.log(this.filter('fastest').pluck('name') + ' has/have the fastest parser');
+});
+
+/**
+ * Start the benchmark, froom frooom!!
+ */
+console.log('Starting the benchmark, parsing ' + length + ' useragent strings per run');
+froomfroom.run();
Please sign in to comment.
Something went wrong with that request. Please try again.