tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

perftest_locale.js (3775B)


      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/. */
      4 // @ts-check
      5 
      6 var perfMetadata = {
      7  owner: "Internationalization Team",
      8  name: "Intl.Locale",
      9  description: "Test the speed of the Intl.Locale implementation.",
     10  options: {
     11    default: {
     12      perfherder: true,
     13      perfherder_metrics: [
     14        {
     15          name: "Intl.Locale constructor iterations",
     16          unit: "iterations",
     17        },
     18        { name: "Intl.Locale constructor accumulatedTime", unit: "ms" },
     19        { name: "Intl.Locale constructor perCallTime", unit: "ms" },
     20 
     21        {
     22          name: "Intl.Locale.prototype accessors iterations",
     23          unit: "iterations",
     24        },
     25        {
     26          name: "Intl.Locale.prototype accessors accumulatedTime",
     27          unit: "ms",
     28        },
     29        {
     30          name: "Intl.Locale.prototype accessors perCallTime",
     31          unit: "ms",
     32        },
     33 
     34        {
     35          name: "Intl.Locale.maximize operation iterations",
     36          unit: "iterations",
     37        },
     38        {
     39          name: "Intl.Locale.maximize operation accumulatedTime",
     40          unit: "ms",
     41        },
     42        {
     43          name: "Intl.Locale.maximize operation perCallTime",
     44          unit: "ms",
     45        },
     46      ],
     47      verbose: true,
     48    },
     49  },
     50  tags: ["intl", "ecma402"],
     51 };
     52 
     53 const maximizeLocales = [
     54  "en-US",
     55  "en-GB",
     56  "es-AR",
     57  "it",
     58  "zh-Hans-CN",
     59  "de-AT",
     60  "pl",
     61  "fr-FR",
     62  "de-AT",
     63  "sr-Cyrl-SR",
     64  "nb-NO",
     65  "fr-FR",
     66  "mk",
     67  "uk",
     68  "und-PL",
     69  "und-Latn-AM",
     70  "ug-Cyrl",
     71  "sr-ME",
     72  "mn-Mong",
     73  "lif-Limb",
     74  "gan",
     75  "zh-Hant",
     76  "yue-Hans",
     77  "unr",
     78  "unr-Deva",
     79  "und-Thai-CN",
     80  "ug-Cyrl",
     81  "en-Latn-DE",
     82  "pl-FR",
     83  "de-CH",
     84  "tuq",
     85  "sr-ME",
     86  "ng",
     87  "klx",
     88  "kk-Arab",
     89  "en-Cyrl",
     90  "und-Cyrl-UK",
     91  "und-Arab",
     92  "und-Arab-FO",
     93 ];
     94 
     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");
     99 
    100  // Split each step of the benchmark into separate JS functions so that performance
    101  // profiles are easy to analyze.
    102 
    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();
    108 
    109      // Measure the constructor.
    110      measureConstructor.start();
    111      const locale = new Intl.Locale(localeString);
    112      measureConstructor.stop();
    113 
    114      benchmarkAccessors(locale);
    115    }
    116  }
    117 
    118  const accessors = [
    119    "basename",
    120    "calendar",
    121    "caseFirst",
    122    "collation",
    123    "hourCycle",
    124    "numeric",
    125    "numberingSystem",
    126    "language",
    127    "script",
    128    "region",
    129  ];
    130 
    131  function benchmarkAccessors(locale) {
    132    for (let j = 0; j < 100; j++) {
    133      measureAccessors.start();
    134      for (let accessor in accessors) {
    135        locale[accessor];
    136      }
    137      measureAccessors.stop();
    138    }
    139  }
    140 
    141  function benchmarkMaximize() {
    142    let locales = [];
    143    for (let localeString of maximizeLocales) {
    144      locales.push(new Intl.Locale(localeString));
    145    }
    146    for (let j = 0; j < 10000; j++) {
    147      measureMaximize.start();
    148      for (let locale of locales) {
    149        locale.maximize();
    150      }
    151      measureMaximize.stop();
    152    }
    153  }
    154 
    155  benchmarkDateTimeFormatConstructor();
    156  benchmarkMaximize();
    157  measureConstructor.reportMetrics();
    158  measureAccessors.reportMetrics();
    159  measureMaximize.reportMetrics();
    160 
    161  ok(true);
    162 });