@@ -5,26 +5,112 @@ title: CPU Leaderboard
55
66# CPU Leaderboard (PassMark CPU Mark)
77
8- <table >
8+ <p >
9+ <label for =" cpuSearch " >Search:</label >
10+ <input id =" cpuSearch " type =" search " placeholder =" e.g. 7800X3D, i7-13700K " style =" min-width : 280px ;" />
11+ </p >
12+
13+ <table id =" cpuTable " >
914 <thead >
1015 <tr>
11- <th>Name</th>
12- <th>Brand</th>
13- <th>Score (CPU Mark)</th>
14- <th>Cores</th>
15- <th>Threads</th>
16+ <th data-sort="name">Name</th>
17+ <th data-sort="brand">Brand</th>
18+ <th data-sort="platform">Platform</th>
19+ <th data-sort="cpu_mark" data-sort-type="number">CPU Mark</th>
20+ <th data-sort="cores" data-sort-type="number">Cores</th>
21+ <th data-sort="threads" data-sort-type="number">Threads</th>
22+ <th>Source</th>
1623 </tr>
1724 </thead >
1825 <tbody >
1926 {% assign sorted = site.data.cpus | sort: "cpu_mark" | reverse %}
2027 {% for cpu in sorted %}
2128 <tr>
22- <td>{{ cpu.name }}</td>
23- <td>{{ cpu.brand }}</td>
24- <td>{{ cpu.cpu_mark }}</td>
25- <td>{{ cpu.cores }}</td>
26- <td>{{ cpu.threads }}</td>
29+ <td class="col-name">{{ cpu.name }}</td>
30+ <td class="col-brand">{{ cpu.brand }}</td>
31+ <td class="col-platform">{{ cpu.platform }}</td>
32+ <td class="col-cpu_mark">{{ cpu.cpu_mark }}</td>
33+ <td class="col-cores">{{ cpu.cores }}</td>
34+ <td class="col-threads">{{ cpu.threads }}</td>
35+ <td>
36+ {% if cpu.source_url and cpu.source_url != "" %}
37+ <a href="{{ cpu.source_url }}" target="_blank" rel="noopener">link</a>
38+ {% else %}
39+ -
40+ {% endif %}
41+ </td>
2742 </tr>
2843 {% endfor %}
2944 </tbody >
3045</table >
46+
47+ <script >
48+ (function () {
49+ const input = document .getElementById (" cpuSearch" );
50+ const table = document .getElementById (" cpuTable" );
51+ const tbody = table .querySelector (" tbody" );
52+ const headers = Array .from (table .querySelectorAll (" thead th[data-sort]" ));
53+
54+ function getCellValue (row , key ) {
55+ const el = row .querySelector (" .col-" + key);
56+ return (el ? el .textContent : " " ).trim ();
57+ }
58+
59+ function normalize (s ) {
60+ return (s || " " ).toLowerCase ();
61+ }
62+
63+ // Search filter
64+ input .addEventListener (" input" , () => {
65+ const q = normalize (input .value );
66+ const rows = Array .from (tbody .querySelectorAll (" tr" ));
67+ rows .forEach (row => {
68+ const text = normalize (row .textContent );
69+ row .style .display = text .includes (q) ? " " : " none" ;
70+ });
71+ });
72+
73+ // Sorting
74+ let currentSort = { key: " cpu_mark" , dir: " desc" , type: " number" };
75+
76+ function parseValue (val , type ) {
77+ if (type === " number" ) {
78+ const n = Number (String (val).replace (/ [^ \d. -] / g , " " ));
79+ return Number .isFinite (n) ? n : - Infinity ;
80+ }
81+ return normalize (val);
82+ }
83+
84+ function sortBy (key , type ) {
85+ const rows = Array .from (tbody .querySelectorAll (" tr" ));
86+
87+ if (currentSort .key === key) {
88+ currentSort .dir = currentSort .dir === " asc" ? " desc" : " asc" ;
89+ } else {
90+ currentSort .key = key;
91+ currentSort .dir = (type === " number" ) ? " desc" : " asc" ;
92+ }
93+ currentSort .type = type || " text" ;
94+
95+ rows .sort ((a , b ) => {
96+ const av = parseValue (getCellValue (a, key), currentSort .type );
97+ const bv = parseValue (getCellValue (b, key), currentSort .type );
98+
99+ if (av < bv) return currentSort .dir === " asc" ? - 1 : 1 ;
100+ if (av > bv) return currentSort .dir === " asc" ? 1 : - 1 ;
101+ return 0 ;
102+ });
103+
104+ // Re-append rows in new order
105+ rows .forEach (r => tbody .appendChild (r));
106+ }
107+
108+ headers .forEach (th => {
109+ const key = th .getAttribute (" data-sort" );
110+ const type = th .getAttribute (" data-sort-type" ) || " text" ;
111+ th .style .cursor = " pointer" ;
112+ th .title = " Click to sort" ;
113+ th .addEventListener (" click" , () => sortBy (key, type));
114+ });
115+ })();
116+ </script >
0 commit comments