diff options
Diffstat (limited to 'files/it/web/api/performance/now/index.html')
| -rw-r--r-- | files/it/web/api/performance/now/index.html | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/files/it/web/api/performance/now/index.html b/files/it/web/api/performance/now/index.html new file mode 100644 index 0000000000..2331157f18 --- /dev/null +++ b/files/it/web/api/performance/now/index.html @@ -0,0 +1,104 @@ +--- +title: performance.now() +slug: Web/API/Performance/now +tags: + - API + - Performance + - Prestazioni + - Reference + - Riferimento + - Web Performance API + - metodo +translation_of: Web/API/Performance/now +--- +<div>{{APIRef("High Resolution Timing")}}</div> + +<p>Il metodo <code><strong>performance.now()</strong></code> restituisce un {{domxref("DOMHighResTimeStamp")}}, misurato in millisecondi.</p> + +<div class="warning"> +<p>The timestamp is not actually high-resolution. To mitigate security threats such as <a href="https://spectreattack.com/">Spectre</a>, browsers currently round the results to varying degrees. (Firefox started rounding to 1 millisecond in Firefox 60.) Some browsers may also slightly randomize the timestamp. The precision may improve again in future releases; browser developers are still investigating these timing attacks and how best to mitigate them.</p> +</div> + +<p>{{AvailableInWorkers}}</p> + +<p>Il valore restituito rappresenta il tempo trascorso dal <a href="/en-US/docs/Web/API/DOMHighResTimeStamp#The_time_origin">time origin</a>.</p> + +<p>Tieni a mente i seguenti punti:</p> + +<ul> + <li>Negli workers dedicati creati da un contesto {{domxref("Window")}}, il valore nel worker sarà minore di <code>performance.now()</code> nella finestra che ha creato quel worker. Prima era lo stesso di <code>t0</code> nel contesto principale, ma è stato cambiato</li> + <li>Negli workers condivisi o di servizio, til valore nel worker potrebbe essere più alto di quello del contesto principale, perché quella finestra può essere creata dopo quegli workers.</li> +</ul> + +<h2 id="Sintassi">Sintassi</h2> + +<pre class="syntaxbox"><em>t</em> = performance.now();</pre> + +<h2 id="Esempio">Esempio</h2> + +<pre class="brush: js">var t0 = performance.now(); +doSomething(); +var t1 = performance.now(); +console.log("Call to doSomething took " + (t1 - t0) + " milliseconds."); +</pre> + +<p>A differenza di altri timing data disponibili con JavaScript (per esempio <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Date/now"><code>Date.now</code></a>), i timestamps restituiti da <code>Performance.now()</code> non sono limitati a una risoluzione di un millisecondo. Invece, rappresentano il tempo come numeri a virgola mobile con una precisione che può arrivare a un microsecondo.</p> + +<p>Inolre, a differenza di <code>Date.now()</code>, il valore restituito da <code>Performance.now()</code> aumenta sempre con costanza, indipendentemente dal clock di sistema (che può essere regolato manualmente o distorto da software come NTP). Altrimenti, <code>performance.timing.navigationStart + performance.now()</code> sarà approssimativamente uguale a <code>Date.now()</code>.</p> + +<h2 id="Reduced_time_precision">Reduced time precision</h2> + +<p>To offer protection against timing attacks and fingerprinting, the precision of <code>performance.now()</code> might get rounded depending on browser settings.<br> + In Firefox, the <code>privacy.reduceTimerPrecision</code> preference is enabled by default and defaults to 1ms.</p> + +<pre class="brush: js">// reduced time precision (1ms) in Firefox 60 +performance.now(); +// 8781416 +// 8781815 +// 8782206 +// ... + + +// reduced time precision with `privacy.resistFingerprinting` enabled +performance.now(); +// 8865400 +// 8866200 +// 8866700 +// ... +</pre> + +<p>In Firefox, you can also enable <code>privacy.resistFingerprinting</code> — this changes the precision to 100ms or the value of <code>privacy.resistFingerprinting.reduceTimerPrecision.microseconds</code>, whichever is larger.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Highres Time Level 2', '#dom-performance-now', 'performance.now()')}}</td> + <td>{{Spec2('Highres Time Level 2')}}</td> + <td>Stricter definitions of interfaces and types.</td> + </tr> + <tr> + <td>{{SpecName('Highres Time', '#dom-performance-now', 'performance.now()')}}</td> + <td>{{Spec2('Highres Time')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.Performance.now")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="http://updates.html5rocks.com/2012/08/When-milliseconds-are-not-enough-performance-now">When milliseconds are not enough: performance.now() </a>from HTML5 Rocks.</li> +</ul> |
