aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/performance/mark/index.md
blob: f589c9759f92ccfa46702aa9ad93396382492c83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
title: performance.mark()
slug: Web/API/Performance/mark
tags:
  - API
  - Method
  - Méthode
  - Reference
  - Performance web
translation_of: Web/API/Performance/mark
---
{{APIRef("User Timing API")}}

La méthode **`mark()`** crée un {{domxref("DOMHighResTimeStamp", "timestamp")}} dans le _tampon d'entrée de performance_ du navigateur avec le nom donné en argument.

L'horodatage ainsi défini par l'application peut être récupéré par l'une des méthodes `getEntries*()` de l'interface {{domxref("Performance")}} ({{domxref("Performance.getEntries", "getEntries()")}}, {{domxref("Performance.getEntriesByName", "getEntriesByName()")}} ou {{domxref("Performance.getEntriesByType", "getEntriesByType()")}}).

La méthode `mark()` stocke ses données en interne sous la forme d'objets {{domxref("PerformanceEntry")}}.

{{AvailableInWorkers}}

## Syntaxe

```js
  performance.mark(name);
```

### Arguments

- `name`
  - : Une chaîne de caractères ({{domxref("DOMString")}}) représentant le nom du marqueur. Si le nom donné à cette méthode existe déjà dans l'interface {{domxref("PerformanceTiming")}}, une exception {{jsxref("SyntaxError")}} est levée.

### Valeur de retour

Aucune.

\>

## Exemple

L'exemple suivant montre comment utiliser `mark()` pour créer et récupérer des entrées {{domxref("PerformanceMark")}}.

```js
// Crée un ensemble de marqueurs.
performance.mark("squirrel");
performance.mark("squirrel");
performance.mark("monkey");
performance.mark("monkey");
performance.mark("dog");
performance.mark("dog");

// Obtient toutes les entrées de PerformanceMark.
const allEntries = performance.getEntriesByType("mark");
console.log(allEntries.length);
// 6

// Obtient toutes les entrées "monkey" de PerformanceMark.
const monkeyEntries = performance.getEntriesByName("monkey");
console.log(monkeyEntries.length);
// 2

// Efface tous les marqueurs.
performance.clearMarks();
```

## Spécifications

| Spécification                                                                                | Statut                                       | Commentaire                                     |
| -------------------------------------------------------------------------------------------- | -------------------------------------------- | ----------------------------------------------- |
| {{SpecName('User Timing Level 2', '#dom-performance-mark', 'mark()')}} | {{Spec2('User Timing Level 2')}} | Clarification du modèle de traitement `mark()`. |
| {{SpecName('User Timing', '#dom-performance-mark', 'mark()')}}         | {{Spec2('User Timing')}}             | Définition initiale.                            |

## Compatibilité des navigateurs

{{Compat("api.Performance.mark")}}