Skip to content
Back to Blog
Performance11 min read

Cloudflare Workers Performance: 5 Key Benchmarks for Beginners

Understand the five performance metrics that matter when running Cloudflare Workers at the edge—cold start time, CPU time limits, memory usage, request latency, and throughput.

Written by Abdul AbrorTechnical Hosting Support Engineer
Cloudflare Workers Performance: 5 Key Benchmarks for Beginners
On this page

When you deploy code to Cloudflare Workers, you're running JavaScript (or WebAssembly) on Cloudflare's edge network instead of a traditional server. Performance matters because every millisecond of delay affects user experience, API response times, and conversion rates. But if you've never benchmarked serverless code before, the terminology can be confusing.

This guide walks through the five performance benchmarks that actually matter for Workers: cold start time, CPU time consumption, memory usage, request latency, and throughput. I'll define each one, explain why it matters, show you how to measure it, and point out the limits you need to stay within.

What makes Workers different from traditional hosting

Cloudflare Workers run at the edge—meaning your code executes in a data center close to the user making the request, not in a single origin server somewhere far away. This cuts latency.

Unlike a traditional VPS or shared hosting environment where your application runs continuously, Workers use an execution model called "serverless." Your code only runs when a request arrives. No request? No running process, no idle CPU cycles, no wasted memory.

That model introduces a concept called cold start. When a Worker hasn't run recently in a particular data center, the runtime has to initialize it before handling the request. Warm starts happen when your Worker is already initialized and can handle requests immediately.

Benchmark 1: Cold start time

Cold start time is how long it takes to spin up your Worker from scratch and execute the first line of code.

For Workers, cold starts are typically fast—often under five milliseconds for simple scripts. That's because Workers use the V8 isolate model instead of spinning up entire containers or virtual machines. An isolate is a lightweight execution context inside an already-running V8 engine. Think of it like opening a new tab in Chrome versus launching the entire browser from shutdown.

Why cold start matters

If your Worker handles API requests for a mobile app, a fifty-millisecond cold start might go unnoticed. But if you're running Workers that manipulate every HTML response for a high-traffic website, even ten milliseconds added to Time to First Byte (TTFB) can hurt Core Web Vitals scores.

Cold starts happen when: - Your Worker hasn't received traffic in a specific edge location for a while (usually minutes). - You just deployed new code. - Cloudflare's runtime evicted your Worker to free up resources.

How to measure cold start

You can't directly measure cold start from inside your Worker code because by the time your code runs, initialization already happened. Instead, measure from the client side.

Use a global monitoring tool that pings your Worker from multiple regions, or write a simple script:

for i in {1..10}; do
  curl -w "@curl-format.txt" -o /dev/null -s https://your-worker.your-subdomain.workers.dev
  sleep 60
done

Create a file called curl-format.txt:

time_total: %{time_total}s\n

The first request after a sixty-second pause will often show a slightly higher total time if a cold start occurred. Compare that to subsequent fast requests (warm starts).

Keeping cold starts low

Minimize the amount of code that runs at the top level (outside your event handlers). Don't import massive libraries or parse large JSON files during initialization. Lazy-load dependencies inside your fetch handler when you actually need them.

Benchmark 2: CPU time per request

Cloudflare gives each Worker request a maximum amount of CPU time. On the free plan, that's ten milliseconds per request. On paid plans, it's fifty milliseconds.

CPU time is not the same as wall-clock time or latency. If your Worker waits for a fetch() call to an external API, that waiting time doesn't count as CPU. Only the time spent actually executing JavaScript (parsing, looping, calculating) counts.

Why CPU time matters

Hit the CPU limit and your Worker terminates immediately with an error. The user sees a 500 response or a Cloudflare error page.

I've seen Workers fail because someone added a JSON parsing loop over a five-thousand-item array, or because a regex backtracked exponentially on malicious input. Both burned through CPU time in milliseconds.

Measuring CPU time

Cloudflare doesn't expose a built-in API to read CPU time from inside your Worker. Instead, check the dashboard's real-time logs or use wrangler tail to stream logs:

wrangler tail --format pretty

Logs will show "outcome": "exceededCpu" if a request hit the limit.

For local development insight, use performance.now() around CPU-heavy code blocks:

const start = performance.now();
// some heavy computation
const end = performance.now();
console.log(`Took ${end - start} ms`);

Remember this measures wall time, not pure CPU time. But it gives you a rough idea of expensive operations.

Staying under the CPU limit

Avoid synchronous operations on large data. Don't parse multi-megabyte JSON in memory. Use streaming APIs when possible. Move heavy computation to a separate service (a durable object, a separate API, or a KV cache) and call it asynchronously.

Benchmark 3: Memory usage per request

Workers have a memory limit of 128 MB per request. That's the total heap size your script can allocate.

Most Workers use far less—often just a few megabytes. But if you load entire files into memory, concatenate large strings in a loop, or cache big objects, you can hit the limit.

Why memory usage matters

Exceed 128 MB and your Worker gets killed mid-request. The user sees an error. Unlike CPU time, there's no paid tier that raises the memory cap. 128 MB is the hard ceiling.

How to measure memory

Again, there's no built-in API to read memory usage from inside a Worker. Use Cloudflare's logs and watch for "outcome": "exceededMemory".

During local development with wrangler dev, you can sometimes spot memory issues if the process slows down or crashes, but it's not a perfect simulation.

The best approach is to think carefully about what you're loading. If you're fetching a file from R2 (Cloudflare's object storage) and it's 50 MB, don't read it into a single string. Stream it.

Keeping memory usage low

Stream responses instead of buffering. Use ReadableStream and TransformStream APIs. Don't store large objects in global variables that persist across requests (Workers reuse isolates, so globals can leak memory between requests).

If you need to manipulate images or large files, do it outside the Worker—use Cloudflare Images, or send the file to a separate processing service.

Benchmark 4: Request latency (end-to-end)

Latency is the total time from when the user sends a request until they receive the first byte of the response. This is Time to First Byte (TTFB).

Workers are designed to minimize latency by running close to users. A Worker that only rewrites a header might add under one millisecond to TTFB. A Worker that fetches data from an external API will add the API's response time plus a bit of overhead.

Why latency matters

Google uses TTFB as part of Core Web Vitals scoring. Slow TTFB degrades user experience, especially on mobile networks. If you're using Workers to proxy or transform content, every millisecond you add is multiplied across millions of requests.

Measuring latency

Measure from the client side or use a synthetic monitoring tool. curl works well:

curl -w "time_starttransfer: %{time_starttransfer}\n" -o /dev/null -s https://your-worker.your-subdomain.workers.dev

time_starttransfer is TTFB.

Alternatively, use WebPageTest or Cloudflare's own analytics dashboard, which shows P50, P95, and P99 latency percentiles for your Workers.

How much latency do Workers add?

For a simple passthrough Worker (one that fetches the origin and returns the response unchanged), expect less than ten milliseconds of added latency globally. If your Worker does complex logic or calls multiple external APIs in series, latency can grow quickly.

Reducing latency

Make external fetch() calls in parallel when possible using Promise.all(). Cache responses in Cloudflare's CDN cache or Workers KV when appropriate. Avoid blocking operations.

Benchmark 5: Throughput (requests per second)

Throughput measures how many requests your Worker can handle concurrently across Cloudflare's entire network. Because Workers scale horizontally and automatically, a single Worker script can handle millions of requests per second if the code is efficient.

Unlike a traditional server where you worry about thread pools or process limits, Workers scale by running many isolates in parallel across many machines.

Why throughput matters

If you're handling API traffic or serving a high-traffic site, you need confidence that your Worker won't become a bottleneck. The good news: Workers rarely bottleneck on concurrency. The bad news: if your Worker is slow or hits CPU/memory limits, those limits apply per request, so even infinite horizontal scale won't help.

Measuring throughput

Use a load testing tool like wrk, k6, or Apache Bench. Run tests from multiple regions to simulate real traffic.

Example with wrk:

wrk -t12 -c400 -d30s https://your-worker.your-subdomain.workers.dev

This runs a thirty-second test with twelve threads and four hundred concurrent connections. The output shows requests per second.

Cloudflare's dashboard also displays request rates in real time. For production traffic, watch the "Requests" graph under the Workers analytics tab.

What affects throughput

CPU time per request is the main bottleneck. If each request burns forty milliseconds of CPU, your Worker will handle fewer requests per second per isolate compared to a Worker that uses two milliseconds per request.

External API calls don't directly hurt throughput because they're async and don't block other requests in the same isolate. But if every request waits five seconds for an external API, your P95 latency will suffer.

So how do you set up your first Worker and start measuring?

Install Wrangler, Cloudflare's CLI:

npm install -g wrangler

Authenticate:

wrangler login

Create a new Worker:

wrangler init my-benchmark-worker

Choose "Fetch handler" when prompted. Wrangler generates a basic Worker template.

Edit src/index.js (or index.ts if you chose TypeScript):

export default {
  async fetch(request, env, ctx) {
    const start = Date.now();

    // Simulate some work
    let sum = 0;
    for (let i = 0; i < 100000; i++) {
      sum += Math.sqrt(i);
    }

    const duration = Date.now() - start;

    return new Response(JSON.stringify({
      message: "Benchmark test",
      computeTime: `${duration}ms`,
      result: sum
    }), {
      headers: { "Content-Type": "application/json" }
    });
  },
};

Test locally:

wrangler dev

Open the URL Wrangler prints (usually http://localhost:8787). You'll see the JSON response with computeTime.

Deploy to Cloudflare's network:

wrangler deploy

Wrangler outputs a workers.dev URL. Hit it with curl or a browser. Now you can measure real latency and throughput from different locations.

What should your benchmarks look like?

For a typical production Worker: - Cold start: under ten milliseconds (often under five). - CPU time per request: under ten milliseconds on average; stay well below the fifty-millisecond paid-plan limit. - Memory usage: under 10 MB for most use cases; watch out for anything approaching 50 MB. - Latency (TTFB): under 100 milliseconds globally, ideally under 50 milliseconds. - Throughput: thousands to millions of requests per second depending on code complexity and traffic distribution.

If your Worker handles simple tasks—rewriting headers, routing requests, or returning cached JSON—you should see single-digit millisecond overhead. If you're doing HTML transformation, API aggregation, or calling external services, expect higher latency but still well under 200 milliseconds in most cases.

Common questions

Can I run long-running background tasks in a Worker?
Not directly. Workers are designed for request-response cycles. For background work, use Durable Objects, Queues, or trigger a separate service.

What happens if I exceed the CPU time limit?
The Worker terminates immediately and the request fails. Users see an error. Check your logs for exceededCpu and optimize your code.

Do Workers share memory or CPU between requests?
No. Each request gets its own isolated context. But isolates can be reused across requests, so global variables can persist (which is why you should avoid storing request-specific data in globals).

How do I monitor Workers performance in production?
Use Cloudflare's analytics dashboard for request rates, error rates, and latency percentiles. For detailed logging, use wrangler tail or send logs to an external service using console.log() and Logpush.

Is there a cost difference between fast and slow Workers?
Cloudflare charges based on request count and CPU time on paid plans. A Worker that uses more CPU per request will cost slightly more, but the bigger cost is hitting limits and having requests fail.

Where to focus first

Start by measuring latency and CPU time. Deploy your Worker, hit it with real requests from different regions, and watch the analytics dashboard. If latency is under 100 milliseconds and you're not seeing exceededCpu errors, you're in good shape.

Then run a load test to confirm throughput. If requests start failing or slowing down under load, profile your code to find hot spots—usually tight loops, large string operations, or synchronous parsing.

Cold start only matters if you're seeing spikes in latency during low-traffic periods. Memory issues are rare unless you're handling large files or leaking objects in globals.

Workers are fast by default. The key is not adding unnecessary work.