本文整理汇总了TypeScript中perf_hooks.performance.now方法的典型用法代码示例。如果您正苦于以下问题:TypeScript performance.now方法的具体用法?TypeScript performance.now怎么用?TypeScript performance.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类perf_hooks.performance
的用法示例。
在下文中一共展示了performance.now方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: perfWrap
async function perfWrap(callback, args?) {
isBuildingStyles = {} // 清空
// 后期可以优化,不编译全部
const t0 = performance.now()
await callback(args)
const t1 = performance.now()
Util.printLog(processTypeEnum.COMPILE, `编译完成,花费${Math.round(t1 - t0)} ms`)
}
示例2: Date
await app.listen(Config.Port, Config.IP, () => {
Log.log.info(`┌`.padEnd(lineLength, '─') + `┐`);
Log.log.info(`│ Server listening: ${Config.ApiUrl}`.padEnd(lineLength, ' ') + `│`);
if (!Config.isProd()) {
Log.log.info(`│ Swagger Documentation: ${Config.ApiUrl}${Config.DocsRoute}`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`│ GraphQL Playground: ${Config.ApiUrl}${Config.GraphRoute}`.padEnd(lineLength, ' ') + `│`);
}
Log.log.info(`├`.padEnd(lineLength, '─') + `┤`);
Log.log.info(`│ Memory: ${readMem()}`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`│ Launch: ${new Date().toISOString()}`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`│ Time to start: ${(performance.now() - startTime).toFixed(3)}ms`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`│ Bootstrap time: ${(performance.now() - bootTime).toFixed(3)}ms`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`└`.padEnd(lineLength, '─') + `┘`);
});
示例3: test
test('decoding and converting to RGB many frames', async (t) => {
const budget = 120000000 / cpuSpeed;
const byteStream = await readOggFile(mediumComplexOggFile);
const startTime = performance.now();
decodeAndConvertAllFrames(byteStream);
const endTime = performance.now();
const runTime = endTime - startTime;
t.true(runTime < budget, `Performance budged exceeded: ${runTime}ms (limit: ${budget})`);
if (runTime < budget) {
t.log(`Performance budget ok: ${runTime}ms (limit: ${budget})`);
}
});
示例4: build
export async function build(appPath, buildConfig: IBuildConfig) {
const {watch} = buildConfig
process.env.TARO_ENV = BUILD_TYPES.RN
fs.ensureDirSync(tempPath)
const t0 = performance.now()
await buildTemp()
const t1 = performance.now()
Util.printLog(processTypeEnum.COMPILE, `编译完成,花费${Math.round(t1 - t0)} ms`)
if (watch) {
watchFiles()
startServerInNewWindow()
} else {
buildBundle()
}
}
示例5:
}).on("complete", () => {
const slowest = suite.filter("slowest").shift();
const fastest = suite.filter("fastest").shift();
console.log(`===\nFastest is ${fastest.name} with ~${mean(fastest)} μs/op`);
if (slowest.name !== fastest.name) {
console.log(`Slowest is ${slowest.name} with ~${mean(slowest)} μs/op`);
}
const d = ((performance.now() - _start)/1000).toFixed(2);
console.log(`Benchmark took ${d} s`);
})
示例6: async
const addMany = (names: string[]): benchmark.Suite => {
for (let name of names) {
for (let file of files) {
suite = suite.add(`${name} -> ${file}`, async () => {
let rfs = await toBench.byName(name).rfs;
rfs.require(file);
});
}
}
_start = performance.now();
return suite;
}
示例7: function
export const logRequest = function(req: express.Request, res: express.Response, next: express.NextFunction) {
const t = performance.now();
const data = Object.assign({}, req.headers);
if (req.query && Object.keys(req.query).length > 0) {
data.querystring = req.query;
}
req.logger.info(`start handling request ${ req.id }: ${ req.method } ${ req.path }`, data);
res.on("finish", () => {
req.logger.info(`finished handling request ${ req.id }`, { time: performance.now() - t });
});
next();
} as express.RequestHandler;
示例8: bootstrap
/**
* Bootstrap the application
*/
async function bootstrap() {
Log.log.debug(` * ${new Date().toISOString()}: Bootstrapping application`);
bootTime = performance.now();
const expressInstance = express();
// Configure Express Instance
expressInstance.use(helmet()); //Helmet
expressInstance.use(bodyParser.urlencoded({ extended: false }));
expressInstance.use(bodyParser.json()); //Body Parser
// Logging
const logDirectory = './log';
existsSync(logDirectory) || mkdirSync(logDirectory); // ensure log directory exists
expressInstance.use(morgan('combined', { stream: Log.stream(logDirectory) }));
morganBody(expressInstance); // Log every request body/response
// Create NestJS APP
Log.log.debug(` * ${new Date().toISOString()}: Creating NestJS app`);
const app = await NestFactory.create(AppModule, new ExpressAdapter(expressInstance), { cors: true, logger: false });
Log.log.debug(` * ${new Date().toISOString()}: Configuring NestJS app`);
app.useLogger(app.get(LogService));
// Global Route Prefix
app.setGlobalPrefix(Config.GlobalRoutePrefix);
// Do not err on fetching favicon (will only be called when surfing the api using a browser)
// which you should not do anyway. You should use a REST explorer like i.e. Postman.
app.use((req, res, next) => req.url === '/favicon.ico' ? res.status(204).send() : next());
// Pipes
app.useGlobalPipes(new ValidationPipe({ transform: true, disableErrorMessages: true }));
// Http-Exception filter
app.useGlobalFilters(new HttpExceptionFilter());
// Interceptors
// Swagger
if (!Config.isProd()) {
Log.log.debug(` * ${new Date().toISOString()}: Setting up swagger`);
const pkg = require('../package.json');
const swagger = await import('@nestjs/swagger');
const options = new swagger.DocumentBuilder()
.setBasePath(Config.GlobalRoutePrefix)
.setTitle(pkg.name)
.setDescription(pkg.description)
.setVersion(pkg.version)
.setContactEmail(pkg.author)
.addBearerAuth(Config.JwtHeaderName, 'header', 'jwt')
.build();
const document = swagger.SwaggerModule.createDocument(app, options);
swagger.SwaggerModule.setup(`/${Config.GlobalRoutePrefix}${Config.DocsRoute}`, app, document);
// Generate .json API Documentation (easly import to Restlet Studio etc...)
const apiDirectory = './api-docs';
existsSync(apiDirectory) || mkdirSync(apiDirectory); // ensure api documentation directory exists
await writeFile(`${apiDirectory}/swagger2.json`, JSON.stringify(document, null, 4), (err: NodeJS.ErrnoException) => {
if (err) throw err;
});
}
// Start listening
await app.listen(Config.Port, Config.IP, () => {
Log.log.info(`┌`.padEnd(lineLength, '─') + `┐`);
Log.log.info(`│ Server listening: ${Config.ApiUrl}`.padEnd(lineLength, ' ') + `│`);
if (!Config.isProd()) {
Log.log.info(`│ Swagger Documentation: ${Config.ApiUrl}${Config.DocsRoute}`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`│ GraphQL Playground: ${Config.ApiUrl}${Config.GraphRoute}`.padEnd(lineLength, ' ') + `│`);
}
Log.log.info(`├`.padEnd(lineLength, '─') + `┤`);
Log.log.info(`│ Memory: ${readMem()}`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`│ Launch: ${new Date().toISOString()}`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`│ Time to start: ${(performance.now() - startTime).toFixed(3)}ms`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`│ Bootstrap time: ${(performance.now() - bootTime).toFixed(3)}ms`.padEnd(lineLength, ' ') + `│`);
Log.log.info(`└`.padEnd(lineLength, '─') + `┘`);
});
}
示例9:
res.on("finish", () => {
req.logger.info(`finished handling request ${ req.id }`, { time: performance.now() - t });
});