Browse Source

bench: misc/url

v0.9.11-release
isaacs 12 years ago
parent
commit
3b16657e77
  1. 14
      benchmark/misc/url.js

14
benchmark/url.js → 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));
}
Loading…
Cancel
Save