ZennyKenny commited on
Commit
ffd7c1e
·
verified ·
1 Parent(s): d34692c

add streaming functionality

Browse files
Files changed (1) hide show
  1. index.html +93 -16
index.html CHANGED
@@ -4,38 +4,115 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Device Performance Checker</title>
 
7
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  function getCPUInfo() {
9
  const start = performance.now();
10
  let sum = 0;
11
  for (let i = 0; i < 1e7; i++) { sum += Math.sqrt(i); }
12
  const end = performance.now();
13
- document.getElementById("cpu-result").innerText = `CPU Benchmark: ${(end - start).toFixed(2)} ms`;
14
  }
15
 
16
  function getGPUInfo() {
17
  const canvas = document.createElement("canvas");
18
  const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
19
- if (!gl) {
20
- document.getElementById("gpu-result").innerText = "WebGL not supported";
21
- return;
 
 
 
 
 
 
 
 
 
22
  }
23
- const debugInfo = gl.getExtension("WEBGL_debug_renderer_info");
24
- const vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
25
- const renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
26
- document.getElementById("gpu-result").innerText = `GPU: ${renderer} (Vendor: ${vendor})`;
27
  }
28
 
29
- function runBenchmarks() {
30
- getCPUInfo();
31
- getGPUInfo();
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
  </script>
 
 
 
 
 
 
 
34
  </head>
35
- <body onload="runBenchmarks()">
36
  <h1>Device Performance Checker</h1>
37
- <p id="cpu-result">CPU Benchmark: Running...</p>
38
- <p id="gpu-result">GPU Info: Detecting...</p>
39
- <button onclick="runBenchmarks()">Re-run Tests</button>
 
 
 
40
  </body>
41
- </html>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Device Performance Checker</title>
7
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
8
  <script>
9
+ let cpuData = [];
10
+ let gpuData = [];
11
+ let labels = [];
12
+ let interval;
13
+ let startTime;
14
+ let chart;
15
+
16
+ function generateChart() {
17
+ const ctx = document.getElementById('performanceChart').getContext('2d');
18
+ chart = new Chart(ctx, {
19
+ type: 'line',
20
+ data: {
21
+ labels: labels,
22
+ datasets: [
23
+ {
24
+ label: 'CPU Time (ms)',
25
+ data: cpuData,
26
+ borderColor: 'red',
27
+ fill: false
28
+ },
29
+ {
30
+ label: 'GPU Load',
31
+ data: gpuData,
32
+ borderColor: 'blue',
33
+ fill: false
34
+ }
35
+ ]
36
+ },
37
+ options: {
38
+ responsive: true,
39
+ maintainAspectRatio: false,
40
+ scales: {
41
+ x: {
42
+ title: {
43
+ display: true,
44
+ text: 'Time (s)'
45
+ }
46
+ },
47
+ y: {
48
+ title: {
49
+ display: true,
50
+ text: 'Performance'
51
+ }
52
+ }
53
+ }
54
+ }
55
+ });
56
+ }
57
+
58
  function getCPUInfo() {
59
  const start = performance.now();
60
  let sum = 0;
61
  for (let i = 0; i < 1e7; i++) { sum += Math.sqrt(i); }
62
  const end = performance.now();
63
+ return end - start;
64
  }
65
 
66
  function getGPUInfo() {
67
  const canvas = document.createElement("canvas");
68
  const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
69
+ if (!gl) return 0;
70
+ return Math.random() * 100; // Mock GPU load percentage
71
+ }
72
+
73
+ function updatePerformanceData() {
74
+ const elapsed = ((performance.now() - startTime) / 1000).toFixed(1);
75
+ labels.push(elapsed);
76
+ cpuData.push(getCPUInfo().toFixed(2));
77
+ gpuData.push(getGPUInfo().toFixed(2));
78
+
79
+ if (chart) {
80
+ chart.update();
81
  }
 
 
 
 
82
  }
83
 
84
+ function startBenchmark() {
85
+ cpuData = [];
86
+ gpuData = [];
87
+ labels = [];
88
+ startTime = performance.now();
89
+
90
+ if (!chart) {
91
+ generateChart();
92
+ }
93
+
94
+ interval = setInterval(updatePerformanceData, 1000);
95
+ }
96
+
97
+ function stopBenchmark() {
98
+ clearInterval(interval);
99
  }
100
  </script>
101
+ <style>
102
+ #chart-container {
103
+ width: 80%;
104
+ height: 400px;
105
+ margin: auto;
106
+ }
107
+ </style>
108
  </head>
109
+ <body>
110
  <h1>Device Performance Checker</h1>
111
+ <p>Click Start to begin performance tracking.</p>
112
+ <button onclick="startBenchmark()">Start</button>
113
+ <button onclick="stopBenchmark()">Stop</button>
114
+ <div id="chart-container">
115
+ <canvas id="performanceChart"></canvas>
116
+ </div>
117
  </body>
118
+ </html>