File size: 12,674 Bytes
96a510f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// Sample data - in a real app, this would come from an API
const cpuData = [
    // Intel 13th Gen
    { id: 1, name: "Intel Core i9-13900K", cores: 24, threads: 32, baseClock: 3.0, boostClock: 5.8, tdp: 125 },
    { id: 2, name: "Intel Core i7-13700K", cores: 16, threads: 24, baseClock: 3.4, boostClock: 5.4, tdp: 125 },
    { id: 3, name: "Intel Core i5-13600K", cores: 14, threads: 20, baseClock: 3.5, boostClock: 5.1, tdp: 125 },
    { id: 4, name: "Intel Core i9-13900", cores: 24, threads: 32, baseClock: 2.0, boostClock: 5.6, tdp: 65 },
    { id: 5, name: "Intel Core i7-13700", cores: 16, threads: 24, baseClock: 2.1, boostClock: 5.2, tdp: 65 },
    { id: 6, name: "Intel Core i5-13600", cores: 14, threads: 20, baseClock: 2.7, boostClock: 5.0, tdp: 65 },

    // Intel 12th Gen
    { id: 7, name: "Intel Core i9-12900K", cores: 16, threads: 24, baseClock: 3.2, boostClock: 5.2, tdp: 125 },
    { id: 8, name: "Intel Core i7-12700K", cores: 12, threads: 20, baseClock: 3.6, boostClock: 5.0, tdp: 125 },
    { id: 9, name: "Intel Core i5-12600K", cores: 10, threads: 16, baseClock: 3.7, boostClock: 4.9, tdp: 125 },
    { id: 10, name: "Intel Core i9-12900", cores: 16, threads: 24, baseClock: 2.4, boostClock: 5.1, tdp: 65 },
    { id: 11, name: "Intel Core i7-12700", cores: 12, threads: 20, baseClock: 2.1, boostClock: 4.9, tdp: 65 },
    { id: 12, name: "Intel Core i5-12600", cores: 6, threads: 12, baseClock: 3.3, boostClock: 4.8, tdp: 65 },

    // AMD Ryzen 7000 Series
    { id: 13, name: "AMD Ryzen 9 7950X", cores: 16, threads: 32, baseClock: 4.5, boostClock: 5.7, tdp: 170 },
    { id: 14, name: "AMD Ryzen 9 7900X", cores: 12, threads: 24, baseClock: 4.7, boostClock: 5.6, tdp: 170 },
    { id: 15, name: "AMD Ryzen 7 7800X3D", cores: 8, threads: 16, baseClock: 4.2, boostClock: 5.0, tdp: 120 },
    { id: 16, name: "AMD Ryzen 7 7700X", cores: 8, threads: 16, baseClock: 4.5, boostClock: 5.4, tdp: 105 },
    { id: 17, name: "AMD Ryzen 5 7600X", cores: 6, threads: 12, baseClock: 4.7, boostClock: 5.3, tdp: 105 },

    // AMD Ryzen 5000 Series
    { id: 18, name: "AMD Ryzen 9 5950X", cores: 16, threads: 32, baseClock: 3.4, boostClock: 4.9, tdp: 105 },
    { id: 19, name: "AMD Ryzen 9 5900X", cores: 12, threads: 24, baseClock: 3.7, boostClock: 4.8, tdp: 105 },
    { id: 20, name: "AMD Ryzen 7 5800X3D", cores: 8, threads: 16, baseClock: 3.4, boostClock: 4.5, tdp: 105 },
    { id: 21, name: "AMD Ryzen 7 5800X", cores: 8, threads: 16, baseClock: 3.8, boostClock: 4.7, tdp: 105 },
    { id: 22, name: "AMD Ryzen 5 5600X", cores: 6, threads: 12, baseClock: 3.7, boostClock: 4.6, tdp: 65 },

    // AMD Ryzen 3000 Series
    { id: 23, name: "AMD Ryzen 9 3950X", cores: 16, threads: 32, baseClock: 3.5, boostClock: 4.7, tdp: 105 },
    { id: 24, name: "AMD Ryzen 9 3900X", cores: 12, threads: 24, baseClock: 3.8, boostClock: 4.6, tdp: 105 },
    { id: 25, name: "AMD Ryzen 7 3800X", cores: 8, threads: 16, baseClock: 3.9, boostClock: 4.5, tdp: 105 },
    { id: 26, name: "AMD Ryzen 7 3700X", cores: 8, threads: 16, baseClock: 3.6, boostClock: 4.4, tdp: 65 },
    { id: 27, name: "AMD Ryzen 5 3600X", cores: 6, threads: 12, baseClock: 3.8, boostClock: 4.4, tdp: 95 },
    { id: 28, name: "AMD Ryzen 5 3600", cores: 6, threads: 12, baseClock: 3.6, boostClock: 4.2, tdp: 65 },

    // Budget Options
    { id: 29, name: "Intel Core i3-13100", cores: 4, threads: 8, baseClock: 3.4, boostClock: 4.5, tdp: 60 },
    { id: 30, name: "Intel Core i3-12100", cores: 4, threads: 8, baseClock: 3.3, boostClock: 4.3, tdp: 60 },
    { id: 31, name: "AMD Ryzen 5 5500", cores: 6, threads: 12, baseClock: 3.6, boostClock: 4.2, tdp: 65 },
    { id: 32, name: "AMD Ryzen 3 3300X", cores: 4, threads: 8, baseClock: 3.8, boostClock: 4.3, tdp: 65 }
];
const gpuData = [
    { id: 1, name: "NVIDIA RTX 4090", vram: 24, baseClock: 2235, boostClock: 2520, tdp: 450 },
    { id: 2, name: "AMD RX 7900 XTX", vram: 24, baseClock: 1900, boostClock: 2500, tdp: 355 },
    { id: 3, name: "NVIDIA RTX 4080", vram: 16, baseClock: 2205, boostClock: 2505, tdp: 320 },
    { id: 4, name: "AMD RX 7900 XT", vram: 20, baseClock: 1500, boostClock: 2400, tdp: 300 },
    { id: 5, name: "NVIDIA RTX 4070 Ti", vram: 12, baseClock: 2310, boostClock: 2610, tdp: 285 },
    { id: 6, name: "AMD RX 7800 XT", vram: 16, baseClock: 1800, boostClock: 2430, tdp: 263 },
    { id: 7, name: "NVIDIA RTX 3090 Ti", vram: 24, baseClock: 1560, boostClock: 1860, tdp: 450 },
    { id: 8, name: "AMD RX 6950 XT", vram: 16, baseClock: 1890, boostClock: 2310, tdp: 335 },
    { id: 9, name: "NVIDIA RTX 3080 Ti", vram: 12, baseClock: 1365, boostClock: 1665, tdp: 350 },
    { id: 10, name: "AMD RX 6800 XT", vram: 16, baseClock: 1825, boostClock: 2250, tdp: 300 },
];

// DOM elements
const cpuList = document.getElementById('cpu-list');
const gpuList = document.getElementById('gpu-list');
const cpuSearch = document.getElementById('cpu-search');
const gpuSearch = document.getElementById('gpu-search');
const calculateBtn = document.getElementById('calculate-btn');
const resultContainer = document.getElementById('result-container');
const selectedCpu = document.getElementById('selected-cpu');
const selectedGpu = document.getElementById('selected-gpu');
const bottleneckPercentage = document.getElementById('bottleneck-percentage');
const bottleneckMeter = document.getElementById('bottleneck-meter');
const recommendations = document.getElementById('recommendations');
const resolutionSelect = document.getElementById('resolution-select');

// Selected components
let selectedCPU = null;
let selectedGPU = null;

// Initialize the component lists
function initComponentLists() {
    renderCPUList(cpuData);
    renderGPUList(gpuData);
}

// Render CPU list
function renderCPUList(cpus) {
    cpuList.innerHTML = '';
    cpus.forEach(cpu => {
        const li = document.createElement('li');
        li.className = 'px-4 py-3 hover:bg-gray-50 cursor-pointer';
        li.dataset.id = cpu.id;
        li.innerHTML = `
            <div class="font-medium">${cpu.name}</div>
            <div class="text-sm text-gray-500">${cpu.cores}C/${cpu.threads}T | ${cpu.baseClock}-${cpu.boostClock}GHz | ${cpu.tdp}W</div>
        `;
        li.addEventListener('click', () => selectComponent(cpu, 'cpu'));
        cpuList.appendChild(li);
    });
}

// Render GPU list
function renderGPUList(gpus) {
    gpuList.innerHTML = '';
    gpus.forEach(gpu => {
        const li = document.createElement('li');
        li.className = 'px-4 py-3 hover:bg-gray-50 cursor-pointer';
        li.dataset.id = gpu.id;
        li.innerHTML = `
            <div class="font-medium">${gpu.name}</div>
            <div class="text-sm text-gray-500">${gpu.vram}GB | ${gpu.baseClock}-${gpu.boostClock}MHz | ${gpu.tdp}W</div>
        `;
        li.addEventListener('click', () => selectComponent(gpu, 'gpu'));
        gpuList.appendChild(li);
    });
}

// Select component
function selectComponent(component, type) {
    // Remove previous selection
    const previousSelected = document.querySelector(`.selected-component[data-type="${type}"]`);
    if (previousSelected) {
        previousSelected.classList.remove('selected-component');
    }

    // Add new selection
    const newSelected = document.querySelector(`[data-id="${component.id}"]`);
    if (newSelected) {
        newSelected.classList.add('selected-component');
        newSelected.setAttribute('data-type', type);
    }

    // Update selected component
    if (type === 'cpu') {
        selectedCPU = component;
        selectedCpu.textContent = component.name;
    } else {
        selectedGPU = component;
        selectedGpu.textContent = component.name;
    }

    // Enable calculate button if both components are selected
    if (selectedCPU && selectedGPU) {
        calculateBtn.disabled = false;
    }
}

// Calculate bottleneck
function calculateBottleneck() {
    if (!selectedCPU || !selectedGPU) return;

    // Show results container
    resultContainer.classList.remove('hidden');

    // Simple bottleneck calculation (this would be more complex in reality)
    // This is a simplified example - real calculation would consider many more factors
    const resolution = parseInt(resolutionSelect.value);
    let cpuScore = (selectedCPU.cores * selectedCPU.threads * selectedCPU.boostClock) / 100;
    let gpuScore = (selectedGPU.vram * selectedGPU.boostClock) / 100;
    
    // Adjust scores based on resolution (higher resolutions are more GPU-bound)
    if (resolution === 1080) {
        cpuScore *= 1.2; // More CPU impact at 1080p
    } else if (resolution === 1440) {
        cpuScore *= 1.0;
        gpuScore *= 1.0;
    } else {
        gpuScore *= 1.2; // More GPU impact at 4K
    }

    const bottleneck = Math.abs((cpuScore - gpuScore) / Math.max(cpuScore, gpuScore) * 100);
    const roundedBottleneck = Math.round(bottleneck);

    // Update UI
    bottleneckPercentage.textContent = `${roundedBottleneck}%`;
    const meterValue = 100 - roundedBottleneck;
    bottleneckMeter.setAttribute('stroke-dasharray', `${meterValue}, 100`);

    // Set meter color based on severity
    if (roundedBottleneck < 10) {
        bottleneckMeter.setAttribute('stroke', '#10b981'); // Green
    } else if (roundedBottleneck < 20) {
        bottleneckMeter.setAttribute('stroke', '#3b82f6'); // Blue
    } else if (roundedBottleneck < 30) {
        bottleneckMeter.setAttribute('stroke', '#f59e0b'); // Yellow
    } else {
        bottleneckMeter.setAttribute('stroke', '#ef4444'); // Red
    }

    // Generate recommendations
    generateRecommendations(roundedBottleneck, cpuScore > gpuScore);
}

// Generate recommendations
function generateRecommendations(bottleneck, isCpuBottleneck) {
    recommendations.innerHTML = '';

    if (bottleneck < 10) {
        const li = document.createElement('li');
        li.className = 'flex items-start';
        li.innerHTML = `
            <i data-feather="check-circle" class="text-green-500 mr-2 mt-0.5"></i>
            <span>Excellent balance! Your components are well-matched.</span>
        `;
        recommendations.appendChild(li);
    } else {
        const severity = bottleneck < 20 ? 'slight' : bottleneck < 30 ? 'moderate' : 'severe';
        const component = isCpuBottleneck ? 'CPU' : 'GPU';

        const li1 = document.createElement('li');
        li1.className = 'flex items-start';
        li1.innerHTML = `
            <i data-feather="alert-circle" class="text-yellow-500 mr-2 mt-0.5"></i>
            <span>${severity.charAt(0).toUpperCase() + severity.slice(1)} ${component} bottleneck detected (${bottleneck}%).</span>
        `;
        recommendations.appendChild(li1);

        const li2 = document.createElement('li');
        li2.className = 'flex items-start';
        li2.innerHTML = `
            <i data-feather="arrow-up" class="text-blue-500 mr-2 mt-0.5"></i>
            <span>Consider upgrading your ${component} for better performance.</span>
        `;
        recommendations.appendChild(li2);

        if (isCpuBottleneck) {
            const li3 = document.createElement('li');
            li3.className = 'flex items-start';
            li3.innerHTML = `
                <i data-feather="monitor" class="text-purple-500 mr-2 mt-0.5"></i>
                <span>Higher resolutions will reduce CPU bottleneck.</span>
            `;
            recommendations.appendChild(li3);
        } else {
            const li3 = document.createElement('li');
            li3.className = 'flex items-start';
            li3.innerHTML = `
                <i data-feather="cpu" class="text-purple-500 mr-2 mt-0.5"></i>
                <span>Your CPU has headroom for a more powerful GPU.</span>
            `;
            recommendations.appendChild(li3);
        }
    }

    feather.replace();
}

// Search functionality
cpuSearch.addEventListener('input', (e) => {
    const searchTerm = e.target.value.toLowerCase();
    const filteredCPUs = cpuData.filter(cpu => 
        cpu.name.toLowerCase().includes(searchTerm)
    );
    renderCPUList(filteredCPUs);
});

gpuSearch.addEventListener('input', (e) => {
    const searchTerm = e.target.value.toLowerCase();
    const filteredGPUs = gpuData.filter(gpu => 
        gpu.name.toLowerCase().includes(searchTerm)
    );
    renderGPUList(filteredGPUs);
});

// Calculate button click
calculateBtn.addEventListener('click', calculateBottleneck);

// Resolution change
resolutionSelect.addEventListener('change', () => {
    if (selectedCPU && selectedGPU) {
        calculateBottleneck();
    }
});

// Initialize
document.addEventListener('DOMContentLoaded', () => {
    initComponentLists();
    calculateBtn.disabled = true;
});