mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 03:07:54 +01:00
util: remove internal mime fns from benchmarks
PR-URL: https://github.com/nodejs/node/pull/50201 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
This commit is contained in:
parent
506858bf13
commit
2e5ffe9fcf
@ -1,53 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [1e7],
|
||||
value: [
|
||||
'application/ecmascript; ',
|
||||
'text/html;charset=gbk',
|
||||
// eslint-disable-next-line max-len
|
||||
'text/html;0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789=x;charset=gbk',
|
||||
],
|
||||
}, {
|
||||
flags: ['--expose-internals'],
|
||||
});
|
||||
|
||||
function main({ n, value }) {
|
||||
|
||||
const parseTypeAndSubtype = require('internal/mime').parseTypeAndSubtype;
|
||||
// Warm up.
|
||||
const length = 1024;
|
||||
const array = [];
|
||||
let errCase = false;
|
||||
|
||||
for (let i = 0; i < length; ++i) {
|
||||
try {
|
||||
array.push(parseTypeAndSubtype(value));
|
||||
} catch (e) {
|
||||
errCase = true;
|
||||
array.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(`errCase: ${errCase}`);
|
||||
bench.start();
|
||||
for (let i = 0; i < n; ++i) {
|
||||
const index = i % length;
|
||||
try {
|
||||
array[index] = parseTypeAndSubtype(value);
|
||||
} catch (e) {
|
||||
array[index] = e;
|
||||
}
|
||||
}
|
||||
|
||||
bench.end(n);
|
||||
|
||||
// Verify the entries to prevent dead code elimination from making
|
||||
// the benchmark invalid.
|
||||
for (let i = 0; i < length; ++i) {
|
||||
assert.strictEqual(typeof array[i], errCase ? 'object' : 'object');
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [1e7],
|
||||
value: [
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'UPPERCASE',
|
||||
'lowercase',
|
||||
'mixedCase',
|
||||
],
|
||||
}, {
|
||||
flags: ['--expose-internals'],
|
||||
});
|
||||
|
||||
function main({ n, value }) {
|
||||
|
||||
const toASCIILower = require('internal/mime').toASCIILower;
|
||||
// Warm up.
|
||||
const length = 1024;
|
||||
const array = [];
|
||||
let errCase = false;
|
||||
|
||||
for (let i = 0; i < length; ++i) {
|
||||
try {
|
||||
array.push(toASCIILower(value));
|
||||
} catch (e) {
|
||||
errCase = true;
|
||||
array.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(`errCase: ${errCase}`);
|
||||
bench.start();
|
||||
|
||||
for (let i = 0; i < n; ++i) {
|
||||
const index = i % length;
|
||||
try {
|
||||
array[index] = toASCIILower(value);
|
||||
} catch (e) {
|
||||
array[index] = e;
|
||||
}
|
||||
}
|
||||
|
||||
bench.end(n);
|
||||
|
||||
// Verify the entries to prevent dead code elimination from making
|
||||
// the benchmark invalid.
|
||||
for (let i = 0; i < length; ++i) {
|
||||
assert.strictEqual(typeof array[i], errCase ? 'object' : 'string');
|
||||
}
|
||||
}
|
@ -384,8 +384,6 @@ ObjectDefineProperty(MIMEType.prototype, 'toJSON', {
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
toASCIILower,
|
||||
parseTypeAndSubtype,
|
||||
MIMEParams,
|
||||
MIMEType,
|
||||
};
|
||||
|
@ -4,8 +4,6 @@
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const { MIMEType, MIMEParams } = require('util');
|
||||
const { toASCIILower } = require('internal/mime');
|
||||
|
||||
|
||||
const WHITESPACES = '\t\n\f\r ';
|
||||
const NOT_HTTP_TOKEN_CODE_POINT = ',';
|
||||
@ -160,8 +158,3 @@ assert.throws(() => params.set(`x${NOT_HTTP_TOKEN_CODE_POINT}`, 'x'), /parameter
|
||||
assert.throws(() => params.set('x', `${NOT_HTTP_QUOTED_STRING_CODE_POINT};`), /parameter value/i);
|
||||
assert.throws(() => params.set('x', `${NOT_HTTP_QUOTED_STRING_CODE_POINT}x`), /parameter value/i);
|
||||
assert.throws(() => params.set('x', `x${NOT_HTTP_QUOTED_STRING_CODE_POINT}`), /parameter value/i);
|
||||
|
||||
assert.strictEqual(toASCIILower('someThing'), 'something');
|
||||
assert.strictEqual(toASCIILower('SomeThing'), 'something');
|
||||
assert.strictEqual(toASCIILower('SomeThing3'), 'something3');
|
||||
assert.strictEqual(toASCIILower('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 'abcdefghijklmnopqrstuvwxyz');
|
||||
|
Loading…
Reference in New Issue
Block a user