Permalink
Browse files

Async vs sync save benchmarks

  • Loading branch information...
1 parent 6086e5f commit 7f0b69e825eb62d216ec44a07f405457be2815e8 @nikhilm committed Mar 22, 2012
Showing with 57 additions and 0 deletions.
  1. +31 −0 async-write.js
  2. +26 −0 sync-write.js
View
@@ -0,0 +1,31 @@
+var taglib = require('./build/Release/taglib');
+var async = require('async');
+var fs = require('fs');
+var match = require('match-files');
+
+var isMp3 = function(path) { return path.match(/\.mp3$/); }
+
+//for (var i = 1; i < 30; i++)
+match.find(process.argv[2], {fileFilters: [isMp3]}, function(err, files) {
+ var t = Date.now();
+ var count = 0;
+ console.log(files.length, "files");
+ async.forEach(files, function(fn, cb) {
+ var tag = taglib.tag(fn, function(err, tag) {
+ if (err)
+ return cb(err);
+ count++;
+ var t = tag.title;
+ var rev = "";
+ for (var i = 0; i < t.length; i++)
+ rev = t[i] + rev;
+ tag.title = rev;
+ tag.save(function(err) {
+ cb(err);
+ });
+ });
+ }, function() {
+ console.log("async", Date.now() - t);
+ console.log("Tag succeeded on", count);
+ });
+});
View
@@ -0,0 +1,26 @@
+var taglib = require('./build/Release/taglib');
+var fs = require('fs');
+var match = require('match-files');
+
+var isMp3 = function(path) { return path.match(/\.mp3$/); }
+
+//for (var i = 0; i < 10; i++)
+match.find(process.argv[2], {fileFilters: [isMp3]}, function(err, files) {
+ var t = Date.now();
+ var count = 0;
+ console.log(files.length, "files");
+ files.forEach(function(fn) {
+ try {
+ var tag = taglib.tagSync(fn);
+ count++;
+ var t = tag.title;
+ var rev = "";
+ for (var i = 0; i < t.length; i++)
+ rev = t[i] + rev;
+ tag.title = rev;
+ tag.saveSync();
+ } catch(e) {}
+ });
+ console.log("sync", Date.now() - t);
+ console.log("Tag succeeded on", count);
+});

0 comments on commit 7f0b69e

Please sign in to comment.