diff --git a/benchmark/url.js b/benchmark/misc/url.js similarity index 74% rename from benchmark/url.js rename to benchmark/misc/url.js index fd8f72c6ea..6c2799b6cb 100644 --- a/benchmark/url.js +++ b/benchmark/misc/url.js @@ -1,5 +1,5 @@ -var util = require('util'); var url = require('url') +var n = 25 * 100; var urls = [ 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj', @@ -18,16 +18,15 @@ var paths = [ benchmark('parse()', url.parse); benchmark('format()', url.format); - paths.forEach(function(p) { - benchmark('resolve("' + p + '")', function(u) { url.resolve(u, p) }); + benchmark('resolve("' + p + '")', function(u) { + url.resolve(u, p) + }); }); function benchmark(name, fun) { - process.stdout.write('benchmarking ' + name + ' ... '); - var timestamp = process.hrtime(); - for (var i = 0; i < 25 * 1000; ++i) { + for (var i = 0; i < n; ++i) { for (var j = 0, k = urls.length; j < k; ++j) fun(urls[j]); } timestamp = process.hrtime(timestamp); @@ -35,6 +34,7 @@ function benchmark(name, fun) { var seconds = timestamp[0]; var nanos = timestamp[1]; var time = seconds + nanos / 1e9; + var rate = n / time; - process.stdout.write(util.format('%s sec\n', time.toFixed(3))); + console.log('misc/url.js %s: %s', name, rate.toPrecision(5)); }