The fastest way from your code to Claude. One file, no SDK.

The hot path to Claude is one HTTPS POST and a stream of six Server-Sent Event types. Each client here writes it by hand in one source file, in one language, and the harness measures what it adds on top of the API: cold start, the turnaround between the two requests of a tool call, memory, and size. The leaderboard sorts by the milliseconds added, fastest first.

Posts about each one are at https://stepinto.dev/claude-hot-path/.

Median of 100 cold starts for each client, under Docker, against the mock server. Client time is every millisecond the mock was not streaming: cold start, turnaround and exit added together.

| Client | Client time | Cold start | Turnaround | Peak memory | Ships | Lines | Post | |---|---|---|---|---|---|---|---| | C | 2.81 ms | 1.3 ms | 0.67 ms | 6.1 MB | 2.1 MB | 271 | | | Rust | 3.16 ms | 1.14 ms | 0.73 ms | 3.0 MB | 3.3 MB | 184 | read | | C#, tuned | 3.35 ms | 1.67 ms | 0.73 ms | 4.3 MB | 10.4 MB | 344 | read | | Zig | 3.67 ms | 1.39 ms | 0.99 ms | 2.3 MB | 488 KB | 179 | read | | Go | 4.42 ms | 1.73 ms | 1.1 ms | 6.4 MB | 5.8 MB | 156 | read | | C#, ahead-of-time | 7.09 ms | 3.01 ms | 1.4 ms | 7.1 MB | 7.8 MB | 102 | read | | bash and curl | 35.3 ms | 6.98 ms | 19.09 ms | 11.8 MB | 23.7 MB | 75 | read | | Python, standard library | 140.37 ms | 123.78 ms | 1.9 ms | 21.2 MB | 35.5 MB | 90 | | | Python, official SDK | 592.47 ms | 464.62 ms | 8.65 ms | 84.1 MB | 71.9 MB | 55 | |

"Ships" is the artefact plus any runtime it needs. The Python SDK row is the reference and is not an entry: it uses the official anthropic package the way its documentation says. The full board, with p95 figures, toolchain versions and the commit each row was measured at, is results/leaderboard.csv.

./bench/bench.sh bash          # build the bash client, check it, measure 100 cold starts
./bench/bench.sh all           # every client, then results/leaderboard.csv

You need Docker and Python 3. You do not need an API key: the mock server in mock/ replays recorded exchanges with their original timing. The only step that talks to Anthropic is recording, which proxies one real exchange through the mock and saves it:

ANTHROPIC_API_KEY=... ./bench/bench.sh record bash

The key is read from your shell by the proxy. The client under test is given a placeholder and never sees it, and nothing writes it to disk.

Every client must do the following, and the bench checks each point rather than trusting the code.

  1. Read the key from ANTHROPIC_API_KEY and the base URL fromANTHROPIC_BASE_URL (defaulthttps://api.anthropic.com ). Nothing else

from the environment.

  1. Read the prompt from stdin.
  2. POST /v1/messages with headersx-api-key ,anthropic-version: 2023-06-01 andcontent-type: application/json , and a body withmodel ,max_tokens ,stream: true ,messages andtools .
  3. Print each text_delta as it arrives. The bench checks that the first

visible byte reached stdout before the mock finished sending the stream that carried it, so buffering the reply, or flushing only on newlines, fails.

  1. Declare one tool, local_time , taking an IANAtimezone . When the stream

ends withstop_reason: "tool_use" , assemble theinput_json_delta fragments, run the tool, send thetool_result in a second request with the assistant turn echoed back, and stream that reply too.

  1. On a non-2xx response, print the body's error.message to stderr and exit

non-zero.

  1. One source file. HTTP and TLS from the platform where it has them. Where it does not, one named library, which counts towards size.

clients/csharp-tuned/ is the same spec written for speed rather than the way the templates say: libc's socket calls and hand-written HTTP/1.1 in place of HttpClient, Utf8JsonReader in place of JsonNode, bare file descriptors in place of Console, _exit in place of runtime shutdown, and a static musl build from scratch. It bends rule 7, so it sits on the board as its own row next to the stock csharp client rather than replacing it.

| Column | Meaning | |---|---| | artefact_bytes | The stripped binary, or the source file for an interpreted language. | | runtime_bytes | Zero for a static binary. The interpreter and any shared runtime otherwise, measured inside the image. | | cold_start_ms | Process spawn to the mock receiving the first request. Median and p95. | | turnaround_ms | First reply finished to second request received: parse the stream, run the tool, build and send the next request. | | tail_ms | Second reply finished to exit. | | client_ms | The sum of the three: every millisecond the mock was not streaming. Median and p95. | | max_rss_kb | Peak resident memory, from the kernel's rusage for the child. | | source_lines | Non-blank, non-comment lines in the one source file. Manifests (Cargo.toml, the csproj) are not counted. | | build_s | Clean image build, reported and not ranked. |

The streaming check uses the same clocks: the runner notes when the first non-whitespace byte reached stdout and the mock notes when it wrote each chunk, and the first must come before the last. On the recorded fixture a streaming client has about 11 ms in hand and a buffering one is 0.3 to 1 ms late, which the check catches. All timings are differences between timestamps the mock recorded and the runner's spawn and exit times, which share a clock because the containers share a kernel. Nothing is subtracted, so the mock's own sleep overshoot never counts against a client. The leaderboard sorts by client_ms, fastest first. Nothing is measured over the network: the one real exchange is for conformance, and no timing from it is published.

Make clients/<name>/ with the source file, a Dockerfile whose ENTRYPOINT runs it, and a meta.env:

NAME=zig
KIND=binary            # interpreted, or sdk for an official-SDK baseline row
ARTIFACT=/app/client   # path inside the image
RUNTIME=''             # interpreter binaries, for interpreted and sdk
RUNTIME_DIRS=''        # directories priced whole, e.g. a stdlib and site-packages
SOURCE=client.zig      # the one file, for the lines column

Write /toolchain.txt in the image during the build; the bench reads it.

Then ./bench/bench.sh <name>. CI runs the mock bench on every pull request.

MIT.

原文来源:github.com