summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/performance/time_fetch.html
blob: a771d4889fc52f63c89f400160724f4e93538257 (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
<!DOCTYPE HTML>
<html>
<head>
<script>

  "use strict";

  async function time_fetch(url) {
    let start = performance.now();
    let res = await fetch(url);
    let elapsed = performance.now() - start;

    return {
      elapsed_ms : elapsed,
      status : res.status,
      data : await res.text()
    };
  }

  async function time_xhr(url) {
    let xhr = new XMLHttpRequest();
    xhr.open("GET", url, false);
    let start = performance.now();
    xhr.send();
    let elapsed = performance.now() - start;

    return {
      elapsed_ms : elapsed,
      status : xhr.status,
      data : xhr.responseText
    }
  }

</script>
</head>
<body>
</body>
</html>