Skip to main content
Glama
benchmark.js•6.43 kB
#!/usr/bin/env node /** * AgentDB Quick Benchmark * Simple performance test that works with the published npm package */ const { performance } = require('perf_hooks'); /** * Format throughput for display */ function formatThroughput(opsPerSec) { if (opsPerSec >= 1000000) { return `${(opsPerSec / 1000000).toFixed(2)}M/sec`; } else if (opsPerSec >= 1000) { return `${(opsPerSec / 1000).toFixed(2)}K/sec`; } else { return `${opsPerSec.toFixed(2)}/sec`; } } /** * Generate random vectors for testing */ function generateVectors(count, dimensions = 128) { const vectors = []; for (let i = 0; i < count; i++) { vectors.push({ id: `vec-${i}`, embedding: Array.from({ length: dimensions }, () => Math.random()), metadata: { index: i, category: `cat-${i % 10}`, timestamp: Date.now() } }); } return vectors; } /** * Run benchmark suite */ async function runBenchmark(options = {}) { const { quick = false, vectors = null } = options; // Determine test sizes based on mode // Note: HNSW index building is O(n log n), so batch sizes > 2000 can be slow const sizes = quick ? { single: 200, batch: 300, queries: 10 } : { single: 500, batch: vectors || 1000, queries: 20 }; console.log('šŸš€ AgentDB Performance Benchmark\n'); console.log(`Mode: ${quick ? 'Quick' : 'Standard'}`); console.log('Testing Native SQLite backend with vector operations...\n'); try { const { SQLiteVectorDB } = require('../dist/index.js'); // Test 1: Database Initialization console.log('šŸ“Š Test 1: Database Initialization'); const initStart = performance.now(); const db = new SQLiteVectorDB({ memoryMode: true }); const initDuration = performance.now() - initStart; console.log(` āœ… Initialized in ${initDuration.toFixed(2)}ms\n`); // Test 2: Single Insert Performance console.log(`šŸ“Š Test 2: Single Insert (${sizes.single.toLocaleString()} vectors)`); const singleVectors = generateVectors(sizes.single, 128); const singleStart = performance.now(); for (const vector of singleVectors) { db.insert(vector); } const singleDuration = performance.now() - singleStart; const singleOps = (sizes.single / singleDuration) * 1000; console.log(` āœ… Duration: ${singleDuration.toFixed(2)}ms`); console.log(` āœ… Throughput: ${formatThroughput(singleOps)}\n`); // Close and recreate database for next test db.close(); const db2 = new SQLiteVectorDB({ memoryMode: true }); // Test 3: Batch Insert Performance console.log(`šŸ“Š Test 3: Batch Insert (${sizes.batch.toLocaleString()} vectors)`); console.log(` ā³ Generating ${sizes.batch.toLocaleString()} random vectors...`); const batchVectors = generateVectors(sizes.batch, 128); console.log(` ā³ Inserting batch (this may take a moment for HNSW indexing)...`); const batchStart = performance.now(); db2.insertBatch(batchVectors); const batchDuration = performance.now() - batchStart; const batchOps = (sizes.batch / batchDuration) * 1000; console.log(` āœ… Duration: ${batchDuration.toFixed(2)}ms (includes HNSW index building)`); console.log(` āœ… Throughput: ${formatThroughput(batchOps)}\n`); // Test 4: Search Performance console.log(`šŸ“Š Test 4: Vector Search (${sizes.queries} queries on ${sizes.batch.toLocaleString()} vectors)`); const queryVector = Array.from({ length: 128 }, () => Math.random()); const searchStart = performance.now(); for (let i = 0; i < sizes.queries; i++) { db2.search(queryVector, 10, 'cosine'); } const searchDuration = performance.now() - searchStart; const avgSearchLatency = searchDuration / sizes.queries; console.log(` āœ… Total: ${searchDuration.toFixed(2)}ms`); console.log(` āœ… Average: ${avgSearchLatency.toFixed(2)}ms per query\n`); // Test 5: Different Similarity Metrics console.log(`šŸ“Š Test 5: Similarity Metrics Comparison (${sizes.batch.toLocaleString()} vectors)`); const metrics = ['cosine', 'euclidean', 'dot']; for (const metric of metrics) { const metricStart = performance.now(); for (let i = 0; i < sizes.queries; i++) { db2.search(queryVector, 10, metric); } const metricDuration = performance.now() - metricStart; console.log(` āœ… ${metric}: ${(metricDuration / sizes.queries).toFixed(2)}ms per query`); } // Test 6: Database Stats console.log('\nšŸ“Š Test 6: Database Statistics'); const stats = db2.stats(); console.log(` āœ… Total Vectors: ${stats.count.toLocaleString()}`); console.log(` āœ… DB Size: ${(stats.size / 1024 / 1024).toFixed(2)} MB`); console.log(` āœ… Size per 1K vectors: ${((stats.size / stats.count) * 1000 / 1024 / 1024).toFixed(3)} MB\n`); db2.close(); // Print Summary console.log('\n\n═══════════════════════════════════════════════════════════'); console.log('šŸ“ˆ BENCHMARK SUMMARY'); console.log('═══════════════════════════════════════════════════════════\n'); console.log('Insert Performance:'); console.log(` - Single Insert: ${formatThroughput(singleOps)}`); console.log(` - Batch ${sizes.batch.toLocaleString()}: ${formatThroughput(batchOps)}`); console.log('\nSearch Performance:'); console.log(` - ${sizes.batch.toLocaleString()} vectors: ${avgSearchLatency.toFixed(2)}ms/query`); console.log('\nMemory Efficiency:'); console.log(` - Size per 1K vectors: ${((stats.size / stats.count) * 1000 / 1024 / 1024).toFixed(3)} MB`); console.log('\n═══════════════════════════════════════════════════════════\n'); console.log('āœ… Benchmark completed successfully!\n'); process.exit(0); } catch (error) { console.error('\nāŒ Benchmark failed:', error.message); console.error('\nStack trace:', error.stack); process.exit(1); } } // Run if executed directly if (require.main === module) { runBenchmark(); } module.exports = { runBenchmark };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/airmcp-com/mcp-standards'

If you have feedback or need assistance with the MCP directory API, please join our Discord server