mirror of https://github.com/nodejs/node.git
bench: misc/url
parent
536ce44689
commit
3b16657e77
|
@ -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…
Reference in New Issue