File size: 26,163 Bytes
94fd192 |
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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Analyzer: Optimization Tool</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#3b82f6',
secondary: '#1e40af',
accent: '#8b5cf6',
success: '#10b981',
warning: '#f59e0b',
error: '#ef4444',
dark: '#0f172a',
light: '#f8fafc'
}
}
}
}
</script>
<style>
.code-editor {
font-family: 'Fira Code', 'Courier New', monospace;
font-size: 14px;
line-height: 1.5;
background-color: #0f172a;
color: #e2e8f0;
border-radius: 0.5rem;
padding: 1rem;
height: 300px;
overflow: auto;
}
.line-number {
color: #4b5563;
user-select: none;
padding-right: 1rem;
}
.token.keyword {
color: #c084fc;
}
.token.function {
color: #93c5fd;
}
.token.comment {
color: #64748b;
}
.token.string {
color: #6ee7b7;
}
.token.number {
color: #fbbf24;
}
.token.operator {
color: #f472b6;
}
.highlight-warning {
background-color: rgba(245, 158, 11, 0.2);
}
.highlight-error {
background-color: rgba(239, 68, 68, 0.2);
}
.highlight-success {
background-color: rgba(16, 185, 129, 0.2);
}
.tab-active {
border-bottom: 2px solid #3b82f6;
color: #3b82f6;
}
.metric-card {
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.metric-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body class="bg-gradient-to-br from-slate-900 to-slate-800 text-slate-100 min-h-screen">
<div class="container mx-auto px-4 py-8">
<header class="text-center mb-12">
<h1 class="text-4xl md:text-5xl font-bold bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent mb-4">
Code Analyzer & Optimizer
</h1>
<p class="text-lg text-slate-300 max-w-3xl mx-auto">
Analyze your code for performance bottlenecks, identify optimization opportunities, and generate enhanced versions with improved efficiency.
</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-12">
<!-- Input Section -->
<div class="bg-slate-800 rounded-xl p-6 shadow-xl">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold flex items-center">
<i class="fas fa-code mr-2 text-blue-400"></i>
Code Input
</h2>
<div class="flex space-x-2">
<button id="loadExampleBtn" class="px-3 py-1 bg-blue-600 hover:bg-blue-700 rounded-lg text-sm transition">
<i class="fas fa-file-import mr-1"></i> Example
</button>
<button id="analyzeBtn" class="px-4 py-2 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 rounded-lg flex items-center">
<i class="fas fa-bolt mr-2"></i> Analyze
</button>
</div>
</div>
<div class="code-editor" id="inputCode">
<div class="line">
<span class="line-number">1</span>
<span class="token keyword">function</span> <span class="token function">bubbleSort</span>(arr) {
</div>
<div class="line">
<span class="line-number">2</span>
<span class="token keyword">const</span> n = arr.length;
</div>
<div class="line">
<span class="line-number">3</span>
<span class="token keyword">for</span> (<span class="token keyword">let</span> i = <span class="token number">0</span>; i < n - <span class="token number">1</span>; i++) {
</div>
<div class="line">
<span class="line-number">4</span>
<span class="token keyword">for</span> (<span class="token keyword">let</span> j = <span class="token number">0</span>; j < n - i - <span class="token number">1</span>; j++) {
</div>
<div class="line">
<span class="line-number">5</span>
<span class="token keyword">if</span> (arr[j] > arr[j + <span class="token number">1</span>]) {
</div>
<div class="line">
<span class="line-number">6</span>
<span class="token keyword">let</span> temp = arr[j];
</div>
<div class="line">
<span class="line-number">7</span>
arr[j] = arr[j + <span class="token number">1</span>];
</div>
<div class="line">
<span class="line-number">8</span>
arr[j + <span class="token number">1</span>] = temp;
</div>
<div class="line">
<span class="line-number">9</span>
}
</div>
<div class="line">
<span class="line-number">10</span>
}
</div>
<div class="line">
<span class="line-number">11</span>
}
</div>
<div class="line">
<span class="line-number">12</span>
<span class="token keyword">return</span> arr;
</div>
<div class="line">
<span class="line-number">13</span>
}
</div>
</div>
</div>
<!-- Results Section -->
<div>
<div class="grid grid-cols-3 gap-4 mb-6">
<div class="metric-card bg-slate-800 rounded-xl p-4 text-center">
<div class="text-2xl font-bold text-blue-400 mb-1">O(n²)</div>
<div class="text-sm text-slate-300">Time Complexity</div>
</div>
<div class="metric-card bg-slate-800 rounded-xl p-4 text-center">
<div class="text-2xl font-bold text-yellow-400 mb-1">High</div>
<div class="text-sm text-slate-300">Memory Usage</div>
</div>
<div class="metric-card bg-slate-800 rounded-xl p-4 text-center">
<div class="text-2xl font-bold text-red-400 mb-1">3</div>
<div class="text-sm text-slate-300">Issues Found</div>
</div>
</div>
<div class="bg-slate-800 rounded-xl p-6 shadow-xl">
<h2 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-chart-line mr-2 text-purple-400"></i>
Performance Analysis
</h2>
<div class="space-y-4">
<div class="border-l-4 border-yellow-500 pl-4 py-2">
<h3 class="font-medium text-yellow-300">Inefficient Algorithm</h3>
<p class="text-sm text-slate-300">Bubble sort has O(n²) time complexity. Consider using a more efficient sorting algorithm like quicksort or mergesort.</p>
</div>
<div class="border-l-4 border-yellow-500 pl-4 py-2">
<h3 class="font-medium text-yellow-300">Redundant Operations</h3>
<p class="text-sm text-slate-300">Array length is accessed multiple times in the loop condition. Cache it in a variable for better performance.</p>
</div>
<div class="border-l-4 border-red-500 pl-4 py-2">
<h3 class="font-medium text-red-300">Memory Inefficiency</h3>
<p class="text-sm text-slate-300">Creating temporary variables for swapping can be replaced with a more efficient destructuring assignment.</p>
</div>
</div>
</div>
</div>
</div>
<div class="bg-slate-800 rounded-xl p-6 shadow-xl mb-12">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl font-semibold flex items-center">
<i class="fas fa-cogs mr-2 text-green-400"></i>
Optimized Code
</h2>
<div class="flex space-x-2">
<button class="px-3 py-1 bg-slate-700 hover:bg-slate-600 rounded-lg text-sm transition">
<i class="fas fa-copy mr-1"></i> Copy
</button>
<button class="px-3 py-1 bg-slate-700 hover:bg-slate-600 rounded-lg text-sm transition">
<i class="fas fa-download mr-1"></i> Export
</button>
</div>
</div>
<div class="flex border-b border-slate-700 mb-4">
<button class="px-4 py-2 font-medium tab-active">JavaScript</button>
<button class="px-4 py-2 font-medium text-slate-400 hover:text-slate-200">Pseudo Code</button>
<button class="px-4 py-2 font-medium text-slate-400 hover:text-slate-200">Performance</button>
</div>
<div class="code-editor" id="optimizedCode">
<div class="line">
<span class="line-number">1</span>
<span class="token keyword">function</span> <span class="token function">quickSort</span>(arr) {
</div>
<div class="line">
<span class="line-number">2</span>
<span class="token keyword">if</span> (arr.length <= <span class="token number">1</span>) {
</div>
<div class="line">
<span class="line-number">3</span>
<span class="token keyword">return</span> arr;
</div>
<div class="line">
<span class="line-number">4</span>
}
</div>
<div class="line">
<span class="line-number">5</span>
<span class="token keyword">const</span> pivot = arr[Math.floor(arr.length / <span class="token number">2</span>)];
</div>
<div class="line">
<span class="line-number">6</span>
<span class="token keyword">const</span> left = [];
</div>
<div class="line">
<span class="line-number">7</span>
<span class="token keyword">const</span> right = [];
</div>
<div class="line">
<span class="line-number">8</span>
<span class="token keyword">const</span> equal = [];
</div>
<div class="line">
<span class="line-number">9</span>
<span class="token comment">// Partition elements</span>
</div>
<div class="line">
<span class="line-number">10</span>
<span class="token keyword">for</span> (<span class="token keyword">let</span> element <span class="token keyword">of</span> arr) {
</div>
<div class="line">
<span class="line-number">11</span>
<span class="token keyword">if</span> (element < pivot) {
</div>
<div class="line">
<span class="line-number">12</span>
left.push(element);
</div>
<div class="line">
<span class="line-number">13</span>
} <span class="token keyword">else</span> <span class="token keyword">if</span> (element > pivot) {
</div>
<div class="line">
<span class="line-number">14</span>
right.push(element);
</div>
<div class="line">
<span class="line-number">15</span>
} <span class="token keyword">else</span> {
</div>
<div class="line">
<span class="line-number">16</span>
equal.push(element);
</div>
<div class="line">
<span class="line-number">17</span>
}
</div>
<div class="line">
<span class="line-number">18</span>
}
</div>
<div class="line">
<span class="line-number">19</span>
<span class="token comment">// Recursively sort subarrays</span>
</div>
<div class="line">
<span class="line-number">20</span>
<span class="token keyword">return</span> [...quickSort(left), ...equal, ...quickSort(right)];
</div>
<div class="line">
<span class="line-number">21</span>
}
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<div class="bg-slate-800 rounded-xl p-6 shadow-xl">
<h2 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-list-check mr-2 text-blue-400"></i>
Optimization Summary
</h2>
<ul class="space-y-3">
<li class="flex items-start">
<i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
<div>
<h3 class="font-medium">Algorithm Improvement</h3>
<p class="text-sm text-slate-300">Replaced bubble sort with quicksort (O(n log n) average case)</p>
</div>
</li>
<li class="flex items-start">
<i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
<div>
<h3 class="font-medium">Memory Optimization</h3>
<p class="text-sm text-slate-300">Reduced memory overhead by partitioning in-place where possible</p>
</div>
</li>
<li class="flex items-start">
<i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
<div>
<h3 class="font-medium">Code Refactoring</h3>
<p class="text-sm text-slate-300">Simplified logic with modern JavaScript features like spread operator</p>
</div>
</li>
<li class="flex items-start">
<i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
<div>
<h3 class="font-medium">Error Handling</h3>
<p class="text-sm text-slate-300">Added boundary condition checks for edge cases</p>
</div>
</li>
</ul>
</div>
<div class="bg-slate-800 rounded-xl p-6 shadow-xl">
<h2 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-chart-bar mr-2 text-purple-400"></i>
Performance Comparison
</h2>
<div class="space-y-4">
<div>
<div class="flex justify-between mb-1">
<span class="text-sm">Time Complexity</span>
<span class="text-sm">Improvement: 90%</span>
</div>
<div class="w-full bg-slate-700 rounded-full h-2.5">
<div class="bg-gradient-to-r from-red-500 to-yellow-500 h-2.5 rounded-full" style="width: 90%"></div>
</div>
<div class="flex justify-between mt-1 text-xs text-slate-400">
<span>O(n²) → O(n log n)</span>
<span>Better</span>
</div>
</div>
<div>
<div class="flex justify-between mb-1">
<span class="text-sm">Memory Usage</span>
<span class="text-sm">Improvement: 60%</span>
</div>
<div class="w-full bg-slate-700 rounded-full h-2.5">
<div class="bg-gradient-to-r from-yellow-500 to-green-500 h-2.5 rounded-full" style="width: 60%"></div>
</div>
<div class="flex justify-between mt-1 text-xs text-slate-400">
<span>High → Medium</span>
<span>Better</span>
</div>
</div>
<div>
<div class="flex justify-between mb-1">
<span class="text-sm">Code Readability</span>
<span class="text-sm">Improvement: 80%</span>
</div>
<div class="w-full bg-slate-700 rounded-full h-2.5">
<div class="bg-gradient-to-r from-green-500 to-teal-500 h-2.5 rounded-full" style="width: 80%"></div>
</div>
<div class="flex justify-between mt-1 text-xs text-slate-400">
<span>Good → Excellent</span>
<span>Better</span>
</div>
</div>
</div>
</div>
</div>
<footer class="mt-16 pt-8 border-t border-slate-800 text-center text-slate-400 text-sm">
<p>Code Analyzer & Optimizer Tool • Version 2.0</p>
<p class="mt-2">Analyzes your code, identifies bottlenecks, and provides optimized solutions for better performance.</p>
</footer>
</div>
<script>
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=S-Dreamer/code-analyzer-optimizer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |