The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { ProjectId } from "@t3tools/contracts"; |
| 2 | import { |
| 3 | getLatestThreadForProject, |
| 4 | sortActiveThreadsByOrderKey, |
| 5 | sortPinnedThreadsByOrderKey, |
| 6 | sortThreads, |
| 7 | } from "@t3tools/client-runtime/state/thread-sort"; |
| 8 | import { formatHourShort, formatRelativeHourShort } from "@t3tools/shared/usageFormat"; |
| 9 | import { describe, test } from "vite-plus/test"; |
| 10 | |
| 11 | const projectId = ProjectId.make("benchmark-project"); |
| 12 | const start = Date.parse("2026-08-11T00:00:00.000Z"); |
| 13 | const threads = Array.from({ length: 1_000 }, (_, index) => { |
| 14 | const timestamp = new Date(start + ((index * 997) % 1_000) * 60_000).toISOString(); |
| 15 | return { |
| 16 | id: `thread-${index}`, |
| 17 | projectId, |
| 18 | archivedAt: null, |
| 19 | createdAt: timestamp, |
| 20 | updatedAt: timestamp, |
| 21 | latestUserMessageAt: timestamp, |
| 22 | unsettledAt: null, |
| 23 | }; |
| 24 | }); |
| 25 | const hours = Array.from({ length: 24 }, (_, index) => |
| 26 | new Date(start + index * 3_600_000).toISOString(), |
| 27 | ); |
| 28 | const referenceTime = "2026-08-12T00:00:00.000Z"; |
| 29 | |
| 30 | describe("client performance", () => { |
| 31 | test("sort 1000 threads by recent activity", async ({ bench }) => { |
| 32 | await bench("sort", () => { |
| 33 | sortThreads(threads, "updated_at"); |
| 34 | }).run(); |
| 35 | }); |
| 36 | test("sort 1000 active threads", async ({ bench }) => { |
| 37 | await bench("sort", () => { |
| 38 | sortActiveThreadsByOrderKey(threads); |
| 39 | }).run(); |
| 40 | }); |
| 41 | test("sort 1000 keyless pinned threads", async ({ bench }) => { |
| 42 | await bench("sort", () => { |
| 43 | sortPinnedThreadsByOrderKey(threads); |
| 44 | }).run(); |
| 45 | }); |
| 46 | test("select latest project thread from 1000 threads", async ({ bench }) => { |
| 47 | await bench("select", () => { |
| 48 | getLatestThreadForProject(threads, projectId, "updated_at"); |
| 49 | }).run(); |
| 50 | }); |
| 51 | test("format 24 hourly usage labels and tooltips", async ({ bench }) => { |
| 52 | await bench("format", () => { |
| 53 | hours.map((hour) => [ |
| 54 | formatHourShort(hour, "America/New_York"), |
| 55 | formatRelativeHourShort(hour, referenceTime, "America/New_York"), |
| 56 | ]); |
| 57 | }).run(); |
| 58 | }); |
| 59 | }); |