This repository has been archived by the owner on Jun 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from mykmelez/merge-node
merge Node
- Loading branch information
Showing
371 changed files
with
7,931 additions
and
10,808 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const assert = require('assert'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
method: ['apply', 'spread', 'call-spread'], | ||
count: [5, 10, 20], | ||
context: ['context', 'null'], | ||
rest: [0, 1], | ||
millions: [5] | ||
}); | ||
|
||
function makeTest(count, rest) { | ||
if (rest) { | ||
return function test(...args) { | ||
assert.strictEqual(count, args.length); | ||
}; | ||
} else { | ||
return function test() { | ||
assert.strictEqual(count, arguments.length); | ||
}; | ||
} | ||
} | ||
|
||
function main(conf) { | ||
const n = +conf.millions * 1e6; | ||
const ctx = conf.context === 'context' ? {} : null; | ||
var fn = makeTest(conf.count, conf.rest); | ||
const args = new Array(conf.count); | ||
var i; | ||
for (i = 0; i < conf.count; i++) | ||
args[i] = i; | ||
|
||
switch (conf.method) { | ||
case 'apply': | ||
bench.start(); | ||
for (i = 0; i < n; i++) | ||
fn.apply(ctx, args); | ||
bench.end(n / 1e6); | ||
break; | ||
case 'spread': | ||
if (ctx !== null) | ||
fn = fn.bind(ctx); | ||
bench.start(); | ||
for (i = 0; i < n; i++) | ||
fn(...args); | ||
bench.end(n / 1e6); | ||
break; | ||
case 'call-spread': | ||
bench.start(); | ||
for (i = 0; i < n; i++) | ||
fn.call(ctx, ...args); | ||
bench.end(n / 1e6); | ||
break; | ||
default: | ||
throw new Error('Unexpected method'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { URLSearchParams } = require('url'); | ||
const querystring = require('querystring'); | ||
|
||
const inputs = { | ||
noencode: 'foo=bar&baz=quux&xyzzy=thud', | ||
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d', | ||
encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud', | ||
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64', | ||
multicharsep: 'foo=bar&&&&&&&&&&baz=quux&&&&&&&&&&xyzzy=thud', | ||
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz', | ||
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' + | ||
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz', | ||
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z' | ||
}; | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: Object.keys(inputs), | ||
method: ['legacy', 'whatwg'], | ||
n: [1e5] | ||
}); | ||
|
||
function useLegacy(n, input) { | ||
querystring.parse(input); | ||
bench.start(); | ||
for (var i = 0; i < n; i += 1) { | ||
querystring.parse(input); | ||
} | ||
bench.end(n); | ||
} | ||
|
||
function useWHATWG(n, input) { | ||
new URLSearchParams(input); | ||
bench.start(); | ||
for (var i = 0; i < n; i += 1) { | ||
new URLSearchParams(input); | ||
} | ||
bench.end(n); | ||
} | ||
|
||
function main(conf) { | ||
const type = conf.type; | ||
const n = conf.n | 0; | ||
const method = conf.method; | ||
|
||
const input = inputs[type]; | ||
if (!input) { | ||
throw new Error('Unknown input type'); | ||
} | ||
|
||
switch (method) { | ||
case 'legacy': | ||
useLegacy(n, input); | ||
break; | ||
case 'whatwg': | ||
useWHATWG(n, input); | ||
break; | ||
default: | ||
throw new Error('Unknown method'); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { URLSearchParams } = require('url'); | ||
const querystring = require('querystring'); | ||
|
||
const inputs = { | ||
noencode: 'foo=bar&baz=quux&xyzzy=thud', | ||
encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d', | ||
encodefake: 'foo=%©ar&baz=%A©uux&xyzzy=%©ud', | ||
encodelast: 'foo=bar&baz=quux&xyzzy=thu%64', | ||
multicharsep: 'foo=bar&&&&&&&&&&baz=quux&&&&&&&&&&xyzzy=thud', | ||
multivalue: 'foo=bar&foo=baz&foo=quux&quuy=quuz', | ||
multivaluemany: 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' + | ||
'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz', | ||
manypairs: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z' | ||
}; | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: Object.keys(inputs), | ||
method: ['legacy', 'whatwg'], | ||
n: [1e5] | ||
}); | ||
|
||
function useLegacy(n, input, prop) { | ||
const obj = querystring.parse(input); | ||
querystring.stringify(obj); | ||
bench.start(); | ||
for (var i = 0; i < n; i += 1) { | ||
querystring.stringify(obj); | ||
} | ||
bench.end(n); | ||
} | ||
|
||
function useWHATWG(n, input, prop) { | ||
const obj = new URLSearchParams(input); | ||
obj.toString(); | ||
bench.start(); | ||
for (var i = 0; i < n; i += 1) { | ||
obj.toString(); | ||
} | ||
bench.end(n); | ||
} | ||
|
||
function main(conf) { | ||
const type = conf.type; | ||
const n = conf.n | 0; | ||
const method = conf.method; | ||
|
||
const input = inputs[type]; | ||
if (!input) { | ||
throw new Error('Unknown input type'); | ||
} | ||
|
||
switch (method) { | ||
case 'legacy': | ||
useLegacy(n, input); | ||
break; | ||
case 'whatwg': | ||
useWHATWG(n, input); | ||
break; | ||
default: | ||
throw new Error('Unknown method'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.