2025-08-26 12:32:21 -07:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
2025-09-30 17:09:15 -07:00
|
|
|
import { Brainy } from './dist/index.js'
|
2025-08-26 12:32:21 -07:00
|
|
|
|
|
|
|
|
async function testMemoryUsage() {
|
|
|
|
|
console.log('Testing memory usage...\n')
|
|
|
|
|
|
|
|
|
|
// Log memory before
|
|
|
|
|
const memBefore = process.memoryUsage()
|
|
|
|
|
console.log('Memory before:', {
|
|
|
|
|
rss: Math.round(memBefore.rss / 1024 / 1024) + ' MB',
|
|
|
|
|
heapUsed: Math.round(memBefore.heapUsed / 1024 / 1024) + ' MB'
|
|
|
|
|
})
|
|
|
|
|
|
2025-09-30 17:09:15 -07:00
|
|
|
const brain = new Brainy({
|
2025-08-26 12:32:21 -07:00
|
|
|
storage: { forceMemoryStorage: true }
|
|
|
|
|
})
|
|
|
|
|
await brain.init()
|
|
|
|
|
console.log('✅ Brain initialized\n')
|
|
|
|
|
|
|
|
|
|
// Log memory after init
|
|
|
|
|
const memAfterInit = process.memoryUsage()
|
|
|
|
|
console.log('Memory after init:', {
|
|
|
|
|
rss: Math.round(memAfterInit.rss / 1024 / 1024) + ' MB',
|
|
|
|
|
heapUsed: Math.round(memAfterInit.heapUsed / 1024 / 1024) + ' MB',
|
|
|
|
|
delta: Math.round((memAfterInit.heapUsed - memBefore.heapUsed) / 1024 / 1024) + ' MB'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Add some data WITHOUT using find()
|
|
|
|
|
console.log('\n📝 Adding data...')
|
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
|
await brain.addNoun(`Item ${i}`, { metadata: { index: i } })
|
|
|
|
|
}
|
|
|
|
|
console.log('✅ Added 5 items\n')
|
|
|
|
|
|
|
|
|
|
// Now try search (not find)
|
|
|
|
|
console.log('🔍 Testing search...')
|
|
|
|
|
const results = await brain.search('Item', { limit: 3 })
|
|
|
|
|
console.log(`Found ${results.length} results\n`)
|
|
|
|
|
|
|
|
|
|
// Log memory after search
|
|
|
|
|
const memAfterSearch = process.memoryUsage()
|
|
|
|
|
console.log('Memory after search:', {
|
|
|
|
|
rss: Math.round(memAfterSearch.rss / 1024 / 1024) + ' MB',
|
|
|
|
|
heapUsed: Math.round(memAfterSearch.heapUsed / 1024 / 1024) + ' MB',
|
|
|
|
|
delta: Math.round((memAfterSearch.heapUsed - memAfterInit.heapUsed) / 1024 / 1024) + ' MB'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await brain.shutdown()
|
|
|
|
|
console.log('\n✅ Test complete!')
|
|
|
|
|
process.exit(0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testMemoryUsage().catch(err => {
|
|
|
|
|
console.error('❌ Error:', err.message)
|
|
|
|
|
process.exit(1)
|
|
|
|
|
})
|