Permalink
Browse files

added benchmark script

  • Loading branch information...
1 parent ea5e4ab commit 7ceb233aa5e4fa9ed1dc95f81ff298a4ddbde9f8 @bcelenza bcelenza committed Feb 6, 2012
Showing with 23 additions and 10 deletions.
  1. +15 −0 benchmark.js
  2. +5 −8 lib/encoder.js
  3. +3 −2 package.json
View
@@ -0,0 +1,15 @@
+var Encoder = require('./qr').Encoder,
+ Benchmark = require('benchmark');
+var encoder = new Encoder;
+var suite = new Benchmark.Suite
+
+suite.add('Encoder#encode()', function(){
+ encoder.encode('node-qr');
+})
+.on('cycle', function(event, bench){
+ console.log(String(bench));
+})
+.on('complete', function(){
+ console.log('Fastest is ' + this.filter('fastest').pluck('name'));
+})
+.run({ 'async': true });
View
@@ -28,7 +28,7 @@ Encoder.prototype.default_options = {
Encoder.prototype.encode = function(value, path, options)
{
// preserve scope in callbacks with self
- var self = this;
+ var self = this, cmd_options, qrencode_args, stdout, stderr, qrencode;
try {
// check for undefined value
@@ -40,7 +40,7 @@ Encoder.prototype.encode = function(value, path, options)
value = new Buffer(value);
// if options are given, override defaults
- var cmd_options = {};
+ cmd_options = {};
if(options == null) options = {};
for(var key in this.default_options) {
cmd_options[key] = (options[key] == undefined) ?
@@ -49,15 +49,15 @@ Encoder.prototype.encode = function(value, path, options)
}
// start with base set of args that we'll always pass
- var qrencode_args = [
+ qrencode_args = [
'-s', cmd_options.dot_size,
'-m', cmd_options.margin,
'-l', cmd_options.level,
'-v', cmd_options.version
];
// if case-sensitivity is disabled, add flag
- if(!cmd_options.case_sensitive) qrencode_args.push('-i')
+ if(!cmd_options.case_sensitive) qrencode_args.push('-i');
// if we have a path, write to the path
// otherwise, it will write to stdout
@@ -71,11 +71,8 @@ Encoder.prototype.encode = function(value, path, options)
// add the value to be encoded
qrencode_args.push(value);
- // create stdout data container
- var stdout, stderr;
-
// spawn the child process
- var qrencode = child_process.spawn(
+ qrencode = child_process.spawn(
'qrencode',
qrencode_args
);
View
@@ -10,7 +10,8 @@
"keywords": ["qr", "qrcode", "qrencode", "qrencoder"],
"main": "./qr.js",
"dependencies": {
- "vows": ">= 0.5.8"
+ "vows": ">= 0.5.8",
+ "benchmark": ""
},
"engines": {
"node": ">= 0.4.0"
@@ -24,6 +25,6 @@
"url": "http://www.opensource.org/licenses/mit-license.php"
},
"scripts": {
- "test": "vows --spec test/*.js"
+ "test": "vows --spec test/*.js",
}
}

0 comments on commit 7ceb233

Please sign in to comment.