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/. */
6 * Create an interface to measure iterations for a micro benchmark. These iterations
7 * will then be reported to the perftest runner.
9 * @param {string} metricName
11 function measureIterations(metricName) {
12 let accumulatedTime = 0;
17 * Start a measurement.
23 * Stop a measurement, and record the elapsed time.
26 accumulatedTime += Cu.now() - now;
30 * Report the metrics to perftest after finishing the microbenchmark.
34 metrics[metricName + " iterations"] = iterations;
35 metrics[metricName + " accumulatedTime"] = accumulatedTime;
36 metrics[metricName + " perCallTime"] = accumulatedTime / iterations;
38 info("perfMetrics", metrics);
45 * A cheap and simple pseudo-random number generator that avoids adding new dependencies.
46 * This function ensures tests are repeatable, but can be fed random configurations.
48 * https://en.wikipedia.org/wiki/Linear_congruential_generator
50 * It has the following distribution for the first 100,000 runs:
63 * @returns {number} float values ranged 0-1
66 _seed = Math.imul(_seed, 22695477) + 1;
67 return (_seed >> 1) / 0x7fffffff + 0.5;
71 * The distribution of locales. The number represents the ratio of total users in that
72 * locale. The numbers should add up to ~1.0.
74 * https://sql.telemetry.mozilla.org/dashboard/firefox-localization
76 const localeDistribution = {
114 * Go through the top Firefox locales, and pick one at random that is representative
115 * of the Firefox population as of 2021-06-03. It uses a pseudo-random number generator
116 * to make the results repeatable.
118 * @returns {string} locale
120 function pickRepresentativeLocale() {
123 for (const [locale, representation] of Object.entries(localeDistribution)) {
124 ratio -= representation;
129 // In case we fall through the "for" loop, return the most common locale.