---
sourceDocument: Référence de l’API Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence de l’API Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Chronomètre : Client

# Chronomètre : Client {#ariaid-title1}

* Rversion finale: Xanadu
* 
* Mis à jour 1 août 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute de lecture

L'API StopWatch fournit des méthodes pour mesurer la durée des opérations.

Vous pouvez utiliser cette API dans les scripts côté client à l'aide des API ListV2 et ListV3 .

## Chronomètre - Chronomètre() {#ariaid-title2}

Crée une instance de la classe StopWatch.
Utilise l'heure actuelle comme heure de début.
{#r_STPW-StopWatch__table_ylm_zl5_lv__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 1. Paramètres]

{#r_STPW-StopWatch__table_ylm_zl5_lv}  

    var sw = new StopWatch();

    // some slow code here
    for(var i=0,j=1;i<100000000;i++) {
        j=Math.sqrt(i*i*j);
    }

    if (sw.getTime() > 500)
        console.log("Long running script. Execution time: [" + sw.toString() + "]");

    sw.restart();

    // some faster code
    for(i=0,j;i<100000;i++) {
        j= i + Math.random() * i;
    }

    console.log("Finished in: " + sw.getTime() + "ms");
    sw.stop();

## Chronomètre - Chronomètre(Date initialDate) {#ariaid-title3}

Crée une instance de la classe StopWatch en utilisant la date spécifiée comme valeur initiale.
{#r_STPW-StopWatch_D__table_vrh_11h_qv__entry__3}

| Nom | Type | Description |
|-|-|-|
| date initiale | Date | Date initiale pour l'objet. |
[Tableau 2. Paramètres]

{#r_STPW-StopWatch_D__table_vrh_11h_qv}

## Chronomètre : getTime() {#ariaid-title4}

Renvoie le nombre de millisecondes écoulées depuis le démarrage du minuteur.
{#r_STPW-getTime__table_vx2_sm5_lv__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 3. Paramètres]

{#r_STPW-getTime__table_vx2_sm5_lv} {#r_STPW-getTime__table_wx2_sm5_lv__entry__2}

| Type | Description |
|-|-|
| Numéro | Temps écoulé depuis le démarrage du minuteur. Unité : Millisecondes |
[Tableau 4. Renvoie]

{#r_STPW-getTime__table_wx2_sm5_lv}  

    var sw = new StopWatch();

    // some slow code here
    for(var i=0,j=1;i<100000000;i++) {
        j=Math.sqrt(i*i*j);
    }

    if (sw.getTime() > 500)
        console.log("Long running script. Execution time: [" + sw.toString() + "]");

    sw.restart();

    // some faster code
    for(i=0,j;i<100000;i++) {
        j= i + Math.random() * i;
    }

    console.log("Finished in: " + sw.getTime() + "ms");
    sw.stop();

## Chronomètre - restart() {#ariaid-title5}

Réinitialise le début du minuteur à l'heure actuelle.
{#r_STPW-restart__table_mkb_fn5_lv__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 5. Paramètres]

{#r_STPW-restart__table_mkb_fn5_lv} {#r_STPW-restart__table_nkb_fn5_lv__entry__2}

| Type | Description |
|-|-|
| nul |   |
[Tableau 6. Renvoie]

{#r_STPW-restart__table_nkb_fn5_lv}  

    var sw = new StopWatch();

    // some slow code here
    for(var i=0,j=1;i<100000000;i++) {
        j=Math.sqrt(i*i*j);
    }

    if (sw.getTime() > 500)
        console.log("Long running script. Execution time: [" + sw.toString() + "]");

    sw.restart();

    // some faster code
    for(i=0,j;i<100000;i++) {
        j= i + Math.random() * i;
    }

    console.log("Finished in: " + sw.getTime() + "ms");
    sw.stop();

## Chronomètre : toString() {#ariaid-title6}

Renvoie le temps écoulé.
{#r_STPW-toString__table_xcm_pn5_lv__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucun |   |   |
[Tableau 7. Paramètres]

{#r_STPW-toString__table_xcm_pn5_lv} {#r_STPW-toString__table_ycm_pn5_lv__entry__2}

| Type | Description |
|-|-|
| Chaîne | Temps écoulé. Format : HH :MM :SS. SSS |
[Tableau 8. Renvoie]

{#r_STPW-toString__table_ycm_pn5_lv}  

    var sw = new StopWatch();

    // some slow code here
    for(var i=0,j=1;i<100000000;i++) {
        j=Math.sqrt(i*i*j);
    }

    if (sw.getTime() > 500)
        console.log("Long running script. Execution time: [" + sw.toString() + "]");

    sw.restart();

    // some faster code
    for(i=0,j;i<100000;i++) {
        j= i + Math.random() * i;
    }

    console.log("Finished in: " + sw.getTime() + "ms");
    sw.stop();


