diff --git a/src/ui_helpers.js b/src/ui_helpers.js index 9469dff..597fd81 100644 --- a/src/ui_helpers.js +++ b/src/ui_helpers.js @@ -358,7 +358,10 @@ export function createDayCard(day) { let tagsHtml = ''; if (matchedTags.length > 0) { - const badges = matchedTags.map(t => `star${escapeHtml(t)}`).join(''); + let badges = ''; + for (const t of matchedTags) { + badges += `star${escapeHtml(t)}`; + } tagsHtml = `
${badges}
`; } diff --git a/tests/benchmark_tags.js b/tests/benchmark_tags.js new file mode 100644 index 0000000..5331af5 --- /dev/null +++ b/tests/benchmark_tags.js @@ -0,0 +1,52 @@ + +const { performance } = require('perf_hooks'); + +function escapeHtml(text) { + // Simple mock for benchmark purposes + return text + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + +function currentImplementation(matchedTags) { + const badges = matchedTags.map(t => `star${escapeHtml(t)}`).join(''); + return `
${badges}
`; +} + +function optimizedImplementation(matchedTags) { + let badges = ''; + for (const t of matchedTags) { + badges += `star${escapeHtml(t)}`; + } + return `
${badges}
`; +} + +const tagSizes = [0, 1, 5, 10, 50]; +const iterations = 100000; + +console.log(`Running benchmark with ${iterations} iterations...`); + +for (const size of tagSizes) { + const tags = Array.from({ length: size }, (_, i) => `Tag ${i}`); + + console.log(`\nTag count: ${size}`); + + // Baseline + const startBaseline = performance.now(); + for (let i = 0; i < iterations; i++) { + currentImplementation(tags); + } + const endBaseline = performance.now(); + console.log(`Baseline (map.join): ${(endBaseline - startBaseline).toFixed(4)}ms`); + + // Optimized + const startOptimized = performance.now(); + for (let i = 0; i < iterations; i++) { + optimizedImplementation(tags); + } + const endOptimized = performance.now(); + console.log(`Optimized (for...of): ${(endOptimized - startOptimized).toFixed(4)}ms`); +}