From 7c73e3ffb7b3a09a2a8ec9c0c5f15012cb8dca2b Mon Sep 17 00:00:00 2001 From: Pedro Nastasi Date: Tue, 10 Feb 2026 15:13:34 +0000 Subject: [PATCH] improve performance measurement in large array test Signed-off-by: Pedro Nastasi --- .../database/operations/stitcher/buildEntitySearch.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend/src/database/operations/stitcher/buildEntitySearch.test.ts b/plugins/catalog-backend/src/database/operations/stitcher/buildEntitySearch.test.ts index 032e7854f7..11fc69aaa1 100644 --- a/plugins/catalog-backend/src/database/operations/stitcher/buildEntitySearch.test.ts +++ b/plugins/catalog-backend/src/database/operations/stitcher/buildEntitySearch.test.ts @@ -15,6 +15,7 @@ */ import { DEFAULT_NAMESPACE, Entity } from '@backstage/catalog-model'; +import { performance } from 'node:perf_hooks'; import { buildEntitySearch, mapToRows, traverse } from './buildEntitySearch'; describe('buildEntitySearch', () => { @@ -58,10 +59,11 @@ describe('buildEntitySearch', () => { const items = Array.from({ length: 500 }, (_, i) => `tag-${i}`); const input = { tags: items }; - const start = Date.now(); + const start = performance.now(); const output = traverse(input); - const elapsed = Date.now() - start; + const elapsed = performance.now() - start; + // Each item produces 2 entries: { key: 'tags', value: 'tag-N' } and { key: 'tags.tag-N', value: true } expect(output).toHaveLength(1000); // Should complete well under 100ms with O(n); O(n²) would be noticeably slower expect(elapsed).toBeLessThan(100);