本文整理汇总了TypeScript中performance-now类的典型用法代码示例。如果您正苦于以下问题:TypeScript performance-now类的具体用法?TypeScript performance-now怎么用?TypeScript performance-now使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了performance-now类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: resolveN
function resolveN(container: Container, times: number) {
const result = {
avg: -1,
max: -1,
min: 9999999999999999
};
const items: number[] = [];
let i = 0;
for (i = 0; i < times; i++) {
const start = now();
container.get(`SOME_ID_${times}`);
const end = now();
const total = end - start;
if (total < result.min) {
result.min = total;
}
if (total > result.max) {
result.max = total;
}
items.push(total);
}
result.avg = items.reduce((p, c) => p + c, 0) / items.length;
return result;
}
开发者ID:inversify,项目名称:InversifyJS,代码行数:32,代码来源:performance.test.ts
示例2: installVsTestPlatformToolFromNetworkShare
// Installs the test platform from a network share path provided by the user. The path should point to a .nupkg file.
public async installVsTestPlatformToolFromNetworkShare(netSharePath: string) {
let vstestPlatformInstalledLocation;
let packageSource;
// Remove all double quotes from the path.
netSharePath = netSharePath.replace(/["]+/g, '');
tl.debug(`Attempting to fetch the vstest platform from the specified network share path ${netSharePath}.`);
if (helpers.pathExistsAsFile(netSharePath)) {
packageSource = path.dirname(netSharePath);
} else {
ci.addToConsolidatedCi('failureReason', constants.packageFileDoesNotExist);
throw new Error(tl.loc('SpecifiedFileDoesNotExist', netSharePath));
}
const fileName = path.basename(netSharePath);
const versionExtractionRegex = constants.versionExtractionRegex;
const regexMatches = versionExtractionRegex.exec(fileName);
if (!regexMatches || regexMatches.length !== 2) {
ci.addToConsolidatedCi('failureReason', constants.unexpectedPackageFileName);
throw new Error(tl.loc('UnexpectedFileName', fileName));
}
const testPlatformVersion = regexMatches[1];
ci.addToConsolidatedCi('testPlatformVersion', testPlatformVersion);
// If the version provided is not an explicit version (ie contains containing wildcards) then throw
if (!toolLib.isExplicitVersion(testPlatformVersion)) {
ci.publishEvent('InvalidVersionSpecified', { version: testPlatformVersion } );
ci.addToConsolidatedCi('failureReason', constants.notExplicitVersion);
throw new Error(tl.loc('ProvideExplicitVersion', testPlatformVersion));
}
console.log(tl.loc('ParsedVersion', testPlatformVersion));
tl.debug(`Looking for version ${testPlatformVersion} in the tools cache.`);
startTime = perf();
// Check cache for the specified version
vstestPlatformInstalledLocation = toolLib.findLocalTool(constants.toolFolderName, testPlatformVersion);
ci.addToConsolidatedCi('cacheLookupTime', perf() - startTime);
// If found in the cache then set the tool location and return
if (!helpers.isNullEmptyOrUndefined(vstestPlatformInstalledLocation)) {
ci.addToConsolidatedCi('firstCacheLookupSucceeded', 'true');
helpers.setVsTestToolLocation(vstestPlatformInstalledLocation);
return;
}
ci.addToConsolidatedCi('firstCacheLookupSucceeded', 'false');
vstestPlatformInstalledLocation = await new NugetDownloadHelper()
.attemptPackageDownload(packageSource, testPlatformVersion, null);
// Set the vstest platform tool location for the vstest task to consume
helpers.setVsTestToolLocation(vstestPlatformInstalledLocation);
}
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:59,代码来源:networkshareinstaller.ts
示例3: acquireAndCacheVsTestPlatformNuget
// Downloads and caches the test platform package
private async acquireAndCacheVsTestPlatformNuget(packageSource: string, testPlatformVersion: string, nugetConfigFilePath: string): Promise<string> {
testPlatformVersion = toolLib.cleanVersion(testPlatformVersion);
const nugetTool = tl.tool(path.join(__dirname, 'nuget.exe'));
let downloadPath = helpers.getTempFolder();
// Ensure Agent.TempDirectory is set
if (!downloadPath) {
throw new Error(tl.loc('ExpectedTempToBeSet'));
}
// Call out a warning if the agent work folder path is longer than 50 characters as anything longer may cause the download to fail
// Note: This upper limit was calculated for a particular test platform package version and is subject to change
if (tl.getVariable(constants.agentWorkFolder) && tl.getVariable(constants.agentWorkFolder).length > 50) {
ci.addToConsolidatedCi('agentWorkDirectoryPathTooLong', 'true');
tl.warning(tl.loc('AgentWorkDirectoryPathTooLong'));
}
// Use as short a path as possible due to nested folders in the package that may potentially exceed the 255 char windows path limit
downloadPath = path.join(downloadPath, constants.toolFolderName);
nugetTool.arg(constants.install).arg(constants.packageId).arg(constants.version).arg(testPlatformVersion).arg(constants.source)
.arg(packageSource).arg(constants.outputDirectory).arg(downloadPath).arg(constants.noCache).arg(constants.directDownload)
.argIf(nugetConfigFilePath, constants.configFile).argIf(nugetConfigFilePath, nugetConfigFilePath).arg(constants.noninteractive);
tl.debug(`Downloading Test Platform version ${testPlatformVersion} from ${packageSource} to ${downloadPath}.`);
startTime = perf();
const resultCode = await nugetTool.exec();
ci.addToConsolidatedCi('downloadTime', perf() - startTime);
tl.debug(`Nuget.exe returned with result code ${resultCode}`);
if (resultCode !== 0) {
tl.error(tl.loc('NugetErrorCode', resultCode));
throw new Error(tl.loc('DownloadFailed', resultCode));
}
// Install into the local tool cache
const toolRoot = path.join(downloadPath, constants.packageId + '.' + testPlatformVersion);
tl.debug(`Caching the downloaded folder ${toolRoot}.`);
startTime = perf();
const vstestPlatformInstalledLocation = await toolLib.cacheDir(toolRoot, constants.toolFolderName, testPlatformVersion);
ci.addToConsolidatedCi('cacheTime', perf() - startTime);
return vstestPlatformInstalledLocation;
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:46,代码来源:nugetdownloadhelper.ts
示例4: registerN
function registerN(times: number) {
const result = {
container: new Container(),
register: -1
};
let i = 0;
for (i = 0; i < times; i++) {
const start = now();
result.container.bind<any>(`SOME_ID_${i}`).toConstantValue({ test: i });
const end = now();
result.register = end - start;
}
return result;
}
开发者ID:inversify,项目名称:InversifyJS,代码行数:18,代码来源:performance.test.ts
示例5: attemptPackageDownload
// Attemps to download the package and on failure looks for the latest stable version already present in the cache
public async attemptPackageDownload(packageSource: string, testPlatformVersion: string, nugetConfigFilePath: string) : Promise<string> {
let vstestPlatformInstalledLocation;
try {
tl.debug(`Could not find ${constants.packageId}.${testPlatformVersion} in the tools cache. Fetching it from nuget.`);
// Download the required version and cache it
vstestPlatformInstalledLocation = await this.acquireAndCacheVsTestPlatformNuget(packageSource,
testPlatformVersion, nugetConfigFilePath);
} catch (error) {
tl.error(tl.loc('TestPlatformDownloadFailed', testPlatformVersion, error));
if ((tl.getInput(constants.packageFeedSelector) === constants.nugetOrg || tl.getInput(constants.packageFeedSelector) === constants.customFeed)
&& tl.getInput(constants.versionSelector) === constants.specificVersion) {
return null;
}
console.log(tl.loc('LatestStableCached'));
testPlatformVersion = 'x';
ci.addToConsolidatedCi('downloadSucceeded', 'false');
ci.publishEvent('DownloadFailed', { action: 'getLatestAvailableInCache', error: error } );
startTime = perf();
// Download failed, look for the latest version available in the cache
vstestPlatformInstalledLocation = toolLib.findLocalTool(constants.toolFolderName, testPlatformVersion);
ci.addToConsolidatedCi('secondCacheLookupTime', perf() - startTime);
// No version found in cache, fail the task
if (!vstestPlatformInstalledLocation || vstestPlatformInstalledLocation === 'undefined') {
ci.addToConsolidatedCi('secondCacheLookupSucceeded', 'false');
ci.addToConsolidatedCi('failureReason', constants.downloadFailed);
tl.error(tl.loc('NoPackageFoundInCache'));
throw new Error(tl.loc('FailedToAcquireTestPlatform'));
}
ci.addToConsolidatedCi('secondCacheLookupSucceeded', 'true');
}
return vstestPlatformInstalledLocation;
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:43,代码来源:nugetdownloadhelper.ts
示例6: getLatestPackageVersionNumber
// Lists the latest version of the package available in the feed specified.
public getLatestPackageVersionNumber(packageSource: string, includePreRelease: boolean, nugetConfigFilePath: string): string {
const nugetTool = tl.tool(path.join(__dirname, 'nuget.exe'));
ci.addToConsolidatedCi('includePreRelease', `${includePreRelease}`);
// Only search by package id if the feed is the offial nuget feed, otherwise search by package name as not all feeds
// support searching by package id
nugetTool.arg(constants.list)
.argIf(packageSource === constants.defaultPackageSource , `packageid:${constants.packageId}`)
.argIf(packageSource !== constants.defaultPackageSource , `${constants.packageId}`)
.argIf(includePreRelease, constants.preRelease)
.arg(constants.noninteractive).arg(constants.source).arg(packageSource)
.argIf(nugetConfigFilePath, constants.configFile)
.argIf(nugetConfigFilePath, nugetConfigFilePath);
startTime = perf();
const result = nugetTool.execSync();
ci.addToConsolidatedCi('ListLatestPackageTime', perf() - startTime);
if (result.code !== 0 || !(result.stderr === null || result.stderr === undefined || result.stderr === '')) {
tl.error(tl.loc('NugetErrorCode', result.code));
ci.addToConsolidatedCi('listingPackagesFailed', 'true');
throw new Error(tl.loc('ListPackagesFailed', result.code, result.stderr, result.stdout));
}
const listOfPackages = result.stdout.split('\r\n');
let version: string;
// parse the version number from the output string
listOfPackages.forEach(nugetPackage => {
if (nugetPackage.split(' ')[0] === constants.packageId) {
version = nugetPackage.split(' ')[1];
return;
}
});
return version;
}
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:40,代码来源:nugetpackageversionhelper.ts
示例7: prepareNugetConfigFile
// Utility function that writes the feed url along with username and password if provided into the specified nuget config file
private prepareNugetConfigFile(packageSource: string, configFilePath: string, username: string, password: string, feedId: string) {
const feedUrl = tl.getInput(constants.customFeed);
tl.debug(`Writing package source details to temp config file ${configFilePath}`);
try {
// Write the skeleton nuget config contents to the config file
fs.writeFileSync(configFilePath, constants.emptyNugetConfig, { encoding: 'utf-8' });
} catch (error) {
ci.addToConsolidatedCi('failureReason', 'configFileWriteFailed');
throw new Error(tl.loc('ConfigFileWriteFailed', configFilePath, error));
}
if (!helpers.isNullEmptyOrUndefined(password) && helpers.isNullEmptyOrUndefined(username)) {
username = constants.defaultUsername;
}
const nugetTool = tl.tool(path.join(__dirname, 'nuget.exe'));
nugetTool.arg(constants.sources).arg(constants.add).arg(constants.noninteractive)
.arg(constants.name).arg(feedId).arg(constants.source).arg(feedUrl)
.arg(constants.validAuthenticationTypes).arg(constants.basic)
.argIf(password, constants.usernameParam).argIf(password, username)
.argIf(password, constants.passwordParam).argIf(password, password)
.argIf(configFilePath, constants.configFile).argIf(configFilePath, configFilePath);
startTime = perf();
const result = nugetTool.execSync();
ci.addToConsolidatedCi('prepareConfigFileTime', perf() - startTime);
if (result.code !== 0 || !(result.stderr === null || result.stderr === undefined || result.stderr === '')) {
ci.addToConsolidatedCi('failureReason', constants.configFileWriteFailed);
throw new Error(tl.loc('ConfigFileWriteFailed', configFilePath, result.stderr));
}
// Assign the feed name we wrote into the config file to the packageSource variable
tl.debug(`Setting the source to feed with id ${feedId} whose details were written to the config file.`);
ci.publishEvent('PackageSourceOverridden', {packageSource: 'customFeed'} );
}
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:40,代码来源:nugetfeedinstaller.ts
示例8: processEvent
function processEvent() {
if (paused) {
return;
}
const time = now();
setTime(time);
if (scheduler.isEmpty()) {
return;
}
let nextEventTime = scheduler.peek().time;
while (nextEventTime < time) {
const eventToProcess = scheduler.shiftNextEntry();
if (!eventToProcess.cancelled) {
if (eventToProcess.f) {
eventToProcess.f(eventToProcess, time, scheduler.add, currentTime);
}
if (eventToProcess.type === 'next') {
eventToProcess.stream.shamefullySendNext(eventToProcess.value);
} else if (eventToProcess.type === 'complete') {
eventToProcess.stream.shamefullySendComplete();
} else if (eventToProcess.type === 'error') {
eventToProcess.stream.shamefullySendError(eventToProcess.error);
} else {
throw new Error('Unhandled event type: ' + eventToProcess.type);
}
}
nextEventTime = (scheduler.peek() && scheduler.peek().time) || Infinity;
}
}
开发者ID:ntilwalli,项目名称:cyclejs,代码行数:36,代码来源:time-driver.ts
示例9: perf
}).catch(() => {
ci.addToConsolidatedCi('executionTime', perf() - startTime);
ci.fireConsolidatedCi();
});
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:4,代码来源:vstestplatformtoolinstaller.ts
示例10: NugetFeedInstaller
case 'customfeed':
tl.debug('Going via custom feed download flow.');
await new NugetFeedInstaller()
.installVsTestPlatformToolFromCustomFeed(packageSource, versionSelectorInput, testPlatformVersion, username, password);
break;
case 'netshare':
tl.debug('Going via net share copy flow.');
await new NetworkShareInstaller().installVsTestPlatformToolFromNetworkShare(networkSharePath);
break;
}
} catch (error) {
ci.publishEvent('Completed', { isSetupSuccessful: 'false' } );
tl.setResult(tl.TaskResult.Failed, error);
return;
}
ci.addToConsolidatedCi('result', constants.installationStatusSucceeded);
}
// Execution start
tl.setResourcePath(path.join(__dirname, 'task.json'));
startTime = perf();
startInstaller().then(() => {
ci.addToConsolidatedCi('executionTime', perf() - startTime);
ci.fireConsolidatedCi();
}).catch(() => {
ci.addToConsolidatedCi('executionTime', perf() - startTime);
ci.fireConsolidatedCi();
});
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:31,代码来源:vstestplatformtoolinstaller.ts
注:本文中的performance-now类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论