/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // @ts-check
function choose(options) { return options[Math.floor(options.length * prng())];
}
function randomizeConfig(config, options) { for (let option in options) {
config[option] = choose(options[option]);
}
}
// Split each step of the benchmark into separate JS functions so that performance // profiles are easy to analyze.
function benchmarkNumberFormatConstructor() { for (let i = 0; i < 1000; i++) { // Create a random configuration powered by a pseudo-random number generator. This // way the configurations will be the same between 2 different runs. const locale = pickRepresentativeLocale(); const style = choose(styles); const nu = choose(numberStyles);
let config = {
style,
nu,
}; if (style == "decimal") {
randomizeConfig(config, decimalOptions);
} elseif (style == "currency") {
randomizeConfig(config, currencyOptions);
} elseif (style == "unit") {
randomizeConfig(config, unitOptions);
}
// Measure the constructor.
measureConstructor.start(); const formatter = Intl.NumberFormat(locale, config); // Also include one format operation to ensure the constructor is de-lazified.
formatter.format(0);
measureConstructor.stop();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.