summaryrefslogtreecommitdiffstats
path: root/intl/benchmarks/perftest_pluralRules.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /intl/benchmarks/perftest_pluralRules.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/benchmarks/perftest_pluralRules.js')
-rw-r--r--intl/benchmarks/perftest_pluralRules.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/intl/benchmarks/perftest_pluralRules.js b/intl/benchmarks/perftest_pluralRules.js
new file mode 100644
index 0000000000..956dd09561
--- /dev/null
+++ b/intl/benchmarks/perftest_pluralRules.js
@@ -0,0 +1,119 @@
+/* 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
+
+var perfMetadata = {
+ owner: "Internationalization Team",
+ name: "Intl.PluralRules",
+ description: "Test the speed of the Intl.PluralRules implementation.",
+ options: {
+ default: {
+ perfherder: true,
+ perfherder_metrics: [
+ {
+ name: "Intl.PluralRules constructor iterations",
+ unit: "iterations",
+ },
+ { name: "Intl.PluralRules constructor accumulatedTime", unit: "ms" },
+ { name: "Intl.PluralRules constructor perCallTime", unit: "ms" },
+
+ {
+ name: "Intl.PluralRules.prototype.select iterations",
+ unit: "iterations",
+ },
+ {
+ name: "Intl.PluralRules.prototype.select accumulatedTime",
+ unit: "ms",
+ },
+ {
+ name: "Intl.PluralRules.prototype.select perCallTime",
+ unit: "ms",
+ },
+
+ {
+ name: "Intl.PluralRules pluralCategories iterations",
+ unit: "iterations",
+ },
+ {
+ name: "Intl.PluralRules pluralCategories accumulatedTime",
+ unit: "ms",
+ },
+ {
+ name: "Intl.PluralRules pluralCategories perCallTime",
+ unit: "ms",
+ },
+ ],
+ verbose: true,
+ },
+ },
+ tags: ["intl", "ecma402"],
+};
+
+add_task(function measure_pluralrules() {
+ const measureConstructor = measureIterations("Intl.PluralRules constructor");
+ const measureSelect = measureIterations("Intl.PluralRules.prototype.select");
+ const measurePluralCategories = measureIterations(
+ "Intl.PluralRules pluralCategories"
+ );
+
+ // Re-use the config between runs.
+
+ const fieldOptions = {
+ type: ["cardinal", "ordinal"],
+ };
+
+ const config = {};
+ function randomizeConfig(name, chance) {
+ const option = fieldOptions[name];
+ if (prng() < chance) {
+ config[name] = option[Math.floor(option.length * prng())];
+ } else {
+ delete config[name];
+ }
+ }
+
+ // Split each step of the benchmark into separate JS functions so that performance
+ // profiles are easy to analyze.
+
+ function benchmarkPluralRulesConstructor() {
+ 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();
+ randomizeConfig("type", 0.5);
+
+ // Measure the constructor.
+ measureConstructor.start();
+ const pr = new Intl.PluralRules(locale, config);
+ measureConstructor.stop();
+
+ benchmarkSelectOperation(pr);
+ benchmarkPluralCategories(pr);
+ }
+ }
+
+ function benchmarkSelectOperation(pr) {
+ // Measure the select operation.
+ for (let j = 0; j < 1000; j++) {
+ // TODO: We may want to extend this to non-integer values in the future.
+ const num = Math.floor(prng() * 10000);
+ measureSelect.start();
+ pr.select(num);
+ measureSelect.stop();
+ }
+ }
+
+ function benchmarkPluralCategories(pr) {
+ measurePluralCategories.start();
+ pr.resolvedOptions().pluralCategories;
+ measurePluralCategories.stop();
+ }
+
+ benchmarkPluralRulesConstructor();
+ measureConstructor.reportMetrics();
+ measureSelect.reportMetrics();
+ measurePluralCategories.reportMetrics();
+
+ ok(true);
+});