From 83b30f4332048c5b1e60705c11245336feea0fb6 Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Thu, 5 Oct 2023 12:07:33 -0600 Subject: [PATCH] Fix benchmarks --- docs/src/content/docs/openapi-fetch/index.md | 14 +++++++------- packages/openapi-fetch/test/index.bench.js | 12 ++++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/src/content/docs/openapi-fetch/index.md b/docs/src/content/docs/openapi-fetch/index.md index f03461ade..5349c1bed 100644 --- a/docs/src/content/docs/openapi-fetch/index.md +++ b/docs/src/content/docs/openapi-fetch/index.md @@ -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) | +| 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. diff --git a/packages/openapi-fetch/test/index.bench.js b/packages/openapi-fetch/test/index.bench.js index c6277d327..12ef412dc 100644 --- a/packages/openapi-fetch/test/index.bench.js +++ b/packages/openapi-fetch/test/index.bench.js @@ -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"; @@ -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 }); @@ -53,7 +57,7 @@ describe("get (only URL)", () => { bench("axios", async () => { await axios.get("/url", { async adapter() { - return "{}"; + return { data: {} }; }, }); }); @@ -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: {} }; }, }); });