1'use strict'; 2const common = require('../common.js'); 3const url = require('url'); 4const assert = require('assert'); 5 6const bench = common.createBenchmark(main, { 7 type: common.urlDataTypes, 8 e: [1], 9}); 10 11function main({ type, e }) { 12 const data = common.bakeUrlData(type, e, false, false).map((i) => url.parse(i)); 13 const obj = url.parse(data[0]); 14 const noDead = { 15 protocol: obj.protocol, 16 auth: obj.auth, 17 host: obj.host, 18 hostname: obj.hostname, 19 port: obj.port, 20 pathname: obj.pathname, 21 search: obj.search, 22 hash: obj.hash, 23 }; 24 const len = data.length; 25 // It's necessary to assign the values to an object 26 // to avoid loop invariant code motion. 27 bench.start(); 28 for (let i = 0; i < len; i++) { 29 const obj = data[i]; 30 noDead.protocol = obj.protocol; 31 noDead.auth = obj.auth; 32 noDead.host = obj.host; 33 noDead.hostname = obj.hostname; 34 noDead.port = obj.port; 35 noDead.pathname = obj.pathname; 36 noDead.search = obj.search; 37 noDead.hash = obj.hash; 38 } 39 bench.end(len); 40 assert.ok(noDead); 41} 42