Primeiro commit do projeto Angular

This commit is contained in:
2026-03-14 20:41:55 +00:00
parent 9bebe1de72
commit 94f4f46395
22413 changed files with 3221690 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
'use strict';
module.exports = ({ a, b }) => a + b;
+117
View File
@@ -0,0 +1,117 @@
const { parseArgs } = require('node:util')
const { Suite, jsonReport, prettyReport } = require('bench-node')
const SUPPORTED_SCOPES = [
'simple',
'simple:async',
'simple:all',
'queue',
'startup',
'all'
]
const SUPPORTED_MODES = ['ops', 'time']
const SUPPORTED_REPORTERS = ['pretty', 'json']
const opts = parseArgs({
allowPositionals: false,
options: {
scope: {
type: 'string',
short: 's',
default: 'simple'
},
mode: {
type: 'string',
short: 'm',
default: 'ops'
},
reporter: {
type: 'string',
short: 'r',
default: 'pretty'
},
verbose: {
type: 'boolean',
default: false
}
}
})
let { mode, reporter, scope, verbose } = opts.values
const print = verbose ? console.log : () => {}
if (scope?.length > 0 && !SUPPORTED_SCOPES.includes(scope)) {
throw new Error(
`Invalid scope: ${scope}. Supported scopes: ${SUPPORTED_SCOPES.join(', ')}`
)
}
if (mode?.length > 0 && !SUPPORTED_MODES.includes(mode)) {
throw new Error(
`Invalid mode: ${mode}. Supported modes: ${SUPPORTED_MODES.join(', ')}`
)
}
if (reporter?.length > 0 && !SUPPORTED_REPORTERS.includes(reporter)) {
throw new Error(
`Invalid reporter: ${reporter}. Supported reporters: ${SUPPORTED_REPORTERS.join(
', '
)}`
)
}
if (scope === 'startup') {
print('[Note!] The startup benchmark is not supported with ops mode.')
mode = 'time'
}
if (scope === 'all') {
print('[Note!] The startup benchmark is not supported with ops mode.')
}
let nested
if (scope.includes(':')) {
const [baseScope, subScope] = scope.split(':')
if (subScope?.length > 0 && subScope !== 'async' && subScope !== 'all') {
throw new Error(
`Invalid sub-scope: ${subScope}. Supported sub-scopes: async, all`
)
}
scope = baseScope
nested = subScope?.length > 0 ? subScope : 'simple'
}
let suite = new Suite({
name: 'Piscina Benchmark',
benchmarkMode: mode,
...(reporter === 'json'
? { reporter: jsonReport }
: { reporter: prettyReport })
})
switch (scope) {
case 'simple':
suite = require('./simple')(suite, nested)
break
case 'queue':
suite = require('./queue')(suite)
break
case 'startup':
suite = require('./startup')(suite)
break
case 'all':
suite = require('./queue')(suite)
suite = require('./simple')(suite, scope === 'all' ? 'all' : nested)
break
default:
throw new Error(`Unsupported scope: ${scope}`)
}
suite.run({ async: true }).then(
() => {
print('Benchmark completed.')
},
err => {
print('Benchmark failed:', err)
}
)
+24
View File
@@ -0,0 +1,24 @@
'use strict'
const { resolve } = require('node:path')
const { Piscina, FixedQueue, ArrayTaskQueue } = require('../../dist')
module.exports = suite => {
const pool = new Piscina({
filename: resolve(__dirname, '..', 'fixtures/add.js'),
taskQueue: new ArrayTaskQueue()
})
const pool2 = new Piscina({
filename: resolve(__dirname, '..', 'fixtures/add.js'),
taskQueue: new FixedQueue()
})
suite.add('queue/array', { maxTime: 1 }, async () => {
await pool.run({ a: 1, b: 2 })
})
suite.add('queue/fixed', { maxTime: 1 }, async () => {
await pool2.run({ a: 1, b: 2 })
})
return suite
}
+29
View File
@@ -0,0 +1,29 @@
'use strict'
const { resolve } = require('node:path')
const { Piscina } = require('../../dist')
const { tasksPerWorker, minThreads } = require('./utils')
module.exports = suite => {
const pool = new Piscina({
filename: resolve(__dirname, '..', 'fixtures/add.js'),
atomics: 'async'
})
const pool2 = new Piscina({
minThreads,
filename: resolve(__dirname, '..', 'fixtures/add.js'),
concurrentTasksPerWorker: tasksPerWorker,
atomics: 'async'
})
suite.add('simple/async/default', { maxTime: 1 }, async () => {
await pool.run({ a: 1, b: 2 })
})
suite.add(`simple/async/customized`, { maxTime: 1 }, async () => {
await pool2.run({ a: 1, b: 2 })
})
return suite
}
+13
View File
@@ -0,0 +1,13 @@
const AsyncSimpleBench = require('./async')
const SimpleBench = require('./simple')
module.exports = (suite, scope = 'simple') => {
switch (scope) {
case 'async':
return AsyncSimpleBench(suite)
case 'simple':
return SimpleBench(suite)
default:
return SimpleBench(AsyncSimpleBench(suite))
}
}
+27
View File
@@ -0,0 +1,27 @@
'use strict'
const { resolve } = require('node:path')
const { Piscina } = require('../../dist')
const { tasksPerWorker, minThreads } = require('./utils')
module.exports = suite => {
const pool = new Piscina({
filename: resolve(__dirname, '..', 'fixtures/add.js')
})
const pool2 = new Piscina({
filename: resolve(__dirname, '..', 'fixtures/add.js'),
concurrentTasksPerWorker: tasksPerWorker,
minThreads
})
suite.add('simple/default', { maxTime: 1 }, async () => {
await pool.run({ a: 1, b: 2 })
})
suite.add('simple/customized', { maxTime: 1 }, async () => {
await pool2.run({ a: 1, b: 2 })
})
return suite
}
+8
View File
@@ -0,0 +1,8 @@
const { availableParallelism } = require('node:os')
const tasksPerWorker = Math.max(1, Math.floor(availableParallelism() / 2))
module.exports = {
tasksPerWorker,
minThreads: Math.min(tasksPerWorker, 2),
maxThreads: availableParallelism() * 1.5
}
+15
View File
@@ -0,0 +1,15 @@
'use strict'
const { resolve } = require('node:path')
const { Piscina } = require('../../dist')
module.exports = suite => {
suite.add('startup/default', { maxTime: 1 }, async () => {
const pool = new Piscina({
filename: resolve(__dirname, '..', 'fixtures/add.js')
})
await pool.run({ a: 1, b: 2 })
})
return suite
}