1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 owner: "Internationalization Team",
9 description: "Test the speed of the Intl.Locale implementation.",
15 name: "Intl.Locale constructor iterations",
18 { name: "Intl.Locale constructor accumulatedTime", unit: "ms" },
19 { name: "Intl.Locale constructor perCallTime", unit: "ms" },
22 name: "Intl.Locale.prototype accessors iterations",
26 name: "Intl.Locale.prototype accessors accumulatedTime",
30 name: "Intl.Locale.prototype accessors perCallTime",
35 name: "Intl.Locale.maximize operation iterations",
39 name: "Intl.Locale.maximize operation accumulatedTime",
43 name: "Intl.Locale.maximize operation perCallTime",
50 tags: ["intl", "ecma402"],
53 const maximizeLocales = [
95 add_task(function measure_locale() {
96 const measureConstructor = measureIterations("Intl.Locale constructor");
97 const measureAccessors = measureIterations("Intl.Locale.prototype accessors");
98 const measureMaximize = measureIterations("Intl.Locale.maximize operation");
100 // Split each step of the benchmark into separate JS functions so that performance
101 // profiles are easy to analyze.
103 function benchmarkDateTimeFormatConstructor() {
104 for (let i = 0; i < 1000; i++) {
105 // Create a random configuration powered by a pseudo-random number generator. This
106 // way the configurations will be the same between 2 different runs.
107 const localeString = pickRepresentativeLocale();
109 // Measure the constructor.
110 measureConstructor.start();
111 const locale = new Intl.Locale(localeString);
112 measureConstructor.stop();
114 benchmarkAccessors(locale);
131 function benchmarkAccessors(locale) {
132 for (let j = 0; j < 100; j++) {
133 measureAccessors.start();
134 for (let accessor in accessors) {
137 measureAccessors.stop();
141 function benchmarkMaximize() {
143 for (let localeString of maximizeLocales) {
144 locales.push(new Intl.Locale(localeString));
146 for (let j = 0; j < 10000; j++) {
147 measureMaximize.start();
148 for (let locale of locales) {
151 measureMaximize.stop();
155 benchmarkDateTimeFormatConstructor();
157 measureConstructor.reportMetrics();
158 measureAccessors.reportMetrics();
159 measureMaximize.reportMetrics();