Skip to content

Instantly share code, notes, and snippets.

View DKB0512's full-sized avatar

DKB DKB0512

View GitHub Profile
@DKB0512
DKB0512 / benchmark.ts
Created October 31, 2025 11:13
benchmark script to compare embedWithLocal functions (Original vs Optimized)
// 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,
@DKB0512
DKB0512 / combineChunkBenchmark.ts
Last active October 30, 2025 17:57
Benchmark to compare combineChunk function - original, optimized (with join) and optimized (without join)
// benchmark.ts
interface Chunk {
text: string;
// other props may exist, but we only use .text
}
// --- Implementations to compare ---
// Original version
@DKB0512
DKB0512 / benchmark.ts
Created October 30, 2025 17:11
Benchmark code to compare aggregateVector funtions
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);
@DKB0512
DKB0512 / benchmark.ts
Created October 30, 2025 10:12
Benchmark script - hash, addFeat and norm
// 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;
};