Performance and timers

Last updated Apr 23, 2026

Background

The Workers runtime supports a subset of the Performance API ↗︎, used to measure timing and performance, as well as timing of subrequests and other operations.

performance.now()

The performance.now() method ↗︎ returns timestamp in milliseconds, representing the time elapsed since performance.timeOrigin.

When Workers are deployed to Cloudflare, as a security measure to mitigate against Spectre attacks, APIs that return timers, including performance.now() ↗︎ and Date.now() ↗︎, only advance or increment after I/O occurs. Consider the following examples:

Time is frozen — start will have the exact same value as end.typescript

const start = performance.now();
for (let i = 0; i < 1e6; i++) {
  // do expensive work
}
const end = performance.now();
const timing = end - start; // 0

Time advances, because a subrequest has occurred between start and end.typescript

const start = performance.now();
const response = await fetch("https://developers.cloudflare.com/");
const end = performance.now();
const timing = end - start; // duration of the subrequest to developers.cloudflare.com

By wrapping a subrequest in calls to performance.now() or Date.now() APIs, you can measure the timing of a subrequest, fetching a key from KV, an object from R2, or any other form of I/O in your Worker.

In local development, however, timers will increment regardless of whether I/O happens or not. This means that if you need to measure timing of a piece of code that is CPU intensive, that does not involve I/O, you can run your Worker locally, via Wrangler, which uses the open-source Workers runtime, workerd ↗︎ — the same runtime that your Worker runs in when deployed to Cloudflare.

performance.timeOrigin

The performance.timeOrigin ↗︎ API is a read-only property that returns a baseline timestamp to base other measurements off of.

In the Workers runtime, the timeOrigin property returns 0.

Was this helpful?

YesNo

On this page

Performance and timers - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/runtime-apis/performance/#page","headline":"Performance and timers","description":"Measure timing, performance, and timing of subrequests and other operations.","url":"https://developers.cloudflare.com/workers/runtime-apis/performance/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/runtime-apis/performance/og.png?v=6a3c5d8a6a2b52bf","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Interface that represents an HTTP request. title: Request image: https://developers.cloudflare.com/workers/runtime-apis/request/og.png?v=d9715d666d09fc6d


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.