This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // benchmark.ts | |
| import { createHash } from 'crypto'; | |
| // --- Mock environment and helper --- | |
| const env = { | |
| local_model_path: '/mock/model', | |
| vec_dim: 64, | |
| // vec_dim: 128, | |
| // vec_dim: 256, | |
| // vec_dim: 768, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // benchmark.ts | |
| interface Chunk { | |
| text: string; | |
| // other props may exist, but we only use .text | |
| } | |
| // --- Implementations to compare --- | |
| // Original version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { performance } from "perf_hooks"; | |
| // --- Original Implementation --- | |
| function aggregateVectorsOriginal(vectors: number[][]): number[] { | |
| if (vectors.length === 0) throw new Error('No vectors to aggregate'); | |
| if (vectors.length === 1) return vectors[0]; | |
| const dim = vectors[0].length; | |
| const result = new Array(dim).fill(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // benchmark_corrected.ts | |
| import { performance } from 'perf_hooks'; | |
| // --- Original Code (from the user's query) --- | |
| const hash = (v: string) => { | |
| let h = 0x811c9dc5; | |
| for (let i = 0; i < v.length; i++) h = Math.imul(h ^ v.charCodeAt(i), 16777619); | |
| return h >>> 0; | |
| }; |