---
sourceDocument: Referência de API do Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/pt-BR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - pt-BR

ft:publication_title :

    - Referência de API do Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Cronômetro - Cliente

# Cronômetro - Cliente {#ariaid-title1}

* Versão de lançamento: Xanadu
* 
* Atualizado 1 de ago. de 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 min. de leitura

A API do StopWatch fornece métodos para medir a duração das operações.

Você pode usar esta API em scripts do lado do cliente usando as APIs ListV2 e ListV3.

## StopWatch - StopWatch() {#ariaid-title2}

Cria uma instância da classe StopWatch.
Usa a hora atual como a hora de início.
{#r_STPW-StopWatch__table_ylm_zl5_lv__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 1. Parâmetros]

{#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();

## StopWatch - StopWatch(Data initialDate) {#ariaid-title3}

Cria uma instância da classe StopWatch usando a data especificada como o valor inicial.
{#r_STPW-StopWatch_D__table_vrh_11h_qv__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| dataInicial | Data | A data inicial do objeto. |
[Tabela 2. Parâmetros]

{#r_STPW-StopWatch_D__table_vrh_11h_qv}

## Cronômetro - getTime() {#ariaid-title4}

Retorna o número de milissegundos desde o início do temporizador.
{#r_STPW-getTime__table_vx2_sm5_lv__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 3. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| Número | Tempo desde o início do temporizador. Unidade: Milissegundos |
[Tabela 4. Retorna]

{#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();

## Cronômetro - restart() {#ariaid-title5}

Redefine o início do temporizador para a hora atual.
{#r_STPW-restart__table_mkb_fn5_lv__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 5. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| vazio |   |
[Tabela 6. Retorna]

{#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();

## Cronômetro - toString() {#ariaid-title6}

Retorna o tempo decorrido.
{#r_STPW-toString__table_xcm_pn5_lv__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| Nenhum |   |   |
[Tabela 7. Parâmetros]

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

| Tipo | Descrição |
|-|-|
| Cadeia de caracteres | Tempo decorrido. Formato: HH:MM:SS.SSS |
[Tabela 8. Retorna]

{#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();


