Skip to content

Fix openapi-fetch benchmarks #1365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/src/content/docs/openapi-fetch/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ description: Get Started with openapi-fetch

openapi-fetch applies your OpenAPI types to the native fetch API via TypeScript. Weighs **2 kb** and has virtually zero runtime. Works with React, Vue, Svelte, or vanilla JS.

| Library | Size (min) | “GET” request |
| :------------------------- | ---------: | :------------------------ |
| openapi-fetch | `2 kB` | `151k` ops/s (fastest) |
| openapi-typescript-fetch | `4 kB` | `99k` ops/s (1.4× slower) |
| axios | `32 kB` | `90k` ops/s (1.6× slower) |
| superagent | `55 kB` | `42k` ops/s (3× slower) |
| openapi-typescript-codegen | `367 kB` | `71k` ops/s (2× slower) |
| Library | Size (min) | “GET” request |
| :------------------------- | ---------: | :------------------------- |
| openapi-fetch | `2 kB` | `200k` ops/s (fastest) |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These probably need a more honest revisit because Vitest’s benchmarking tool seems to still be pretty unreliable. The absolute numbers are pretty dubious (they fluctuate pretty wildly between runs), but the relative numbers seem to be somewhat consistent (whatever the fastest # is, the other numbers seem to be proportionately consistent).

No shenanigans here at all to try and inflate openapi-fetch’s performance metrics. But would like to invest more time in here to produce reproduceable results.

| openapi-typescript-fetch | `4 kB` | `100k` ops/s (2× slower) |
| axios | `32 kB` | `165k` ops/s (1.2× slower) |
| superagent | `55 kB` | `50k` ops/s (6.6× slower) |
| openapi-typescript-codegen | `367 kB` | `75k` ops/s (2.6× slower) |

The syntax is inspired by popular libraries like react-query or Apollo client, but without all the bells and whistles and in a 2 kb package.

Expand Down
12 changes: 8 additions & 4 deletions packages/openapi-fetch/test/index.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Fetcher } from "openapi-typescript-fetch";
import superagent from "superagent";
import { afterAll, bench, describe, vi } from "vitest";
import createFetchMock from "vitest-fetch-mock";
import * as openapiTSCodegen from "./openapi-typescript-codegen.min.js";
import createClient from "../dist/index.js";
import * as openapiTSCodegen from "./openapi-typescript-codegen.min.js";

const BASE_URL = "https://api.test.local";

Expand All @@ -26,7 +26,11 @@ describe("setup", () => {
fetcher.path("/pet/findByStatus").method("get").create();
});

// axios: N/A
bench("axios", async () => {
axios.create({
baseURL: "https://api.test.local",
});
});

// superagent: N/A
});
Expand All @@ -53,7 +57,7 @@ describe("get (only URL)", () => {
bench("axios", async () => {
await axios.get("/url", {
async adapter() {
return "{}";
return { data: {} };
},
});
});
Expand Down Expand Up @@ -86,7 +90,7 @@ describe("get (headers)", () => {
await axios.get(`${BASE_URL}/url`, {
headers: { "x-header-1": 123, "x-header-2": 456 },
async adapter() {
return "{}";
return { data: {} };
},
});
});
Expand Down