To obtain the CPU usage of the current system, if HTA is allowed, you can use the followingCodeObtain the current CPU usage (more accurate)
Setinterval (function () {var locator = new activexobject ("wbemscripting. swbemlocator "); var service = locator. connectserver (". "); var CPU = new enumerator (service. execquery ("select * From win32_processor ")). item (); document. title = CPU. loadpercentage;}, 1000 );
If the above method is not allowed, is there a more appropriate method in a normal webpage for rough estimation? The idea is to use a timer. Assume that the execution interval is 500 ms. When you call it, you can determine the time from the start time to the execution time, if the difference between the two is = 500, it can be considered as normal. If the difference is greater than 500, the CPU is busy for different values (because different machines, the CPU processing capability is not the same, so this is only a rough estimation that is not completely accurate and highly dependent on some system parameters)
function cpusimulator () {var J = 100, getnow = function () {return new date (). gettime ();};! (Function () {var I = document. createelement ("Div"), S = 50, FN = function (l) {L = 1; var now = getnow (); var c = 1; while (C
D + C * s) {L ++;} c ++;} d = getnow (); I. innerhtml = "CPU:" + L/J * 100 + "%" ;}, T = setinterval (FN, 500), D = getnow (); I .style.css text = "width: 80px; Height: 20px; position: fixed! Important; _ Position: absolute; top: 10px; Right: 10px; Border: 1px solid #406c99; padding: 2px; color: # f00; "; document. body. appendchild (I); FN () ;}) () ;}
If you want to determine more accurately, you can only adjust the timer execution time and the comparison of the difference. Some people have already written such an example on ajax.com a few years ago. It is relatively easy to use. Enter JavaScript :( function (s) {S. type = 'text/JavaScript '; s. src = 'HTTP: // www.3site. EU/JPU/ijpu. js'; document. getelementsbytagname ('head') [0]. appendchild (s)}) (document. createelement ('script'); a small icon is displayed in the upper-right corner of the current page, which has five levels, here is an online example of the current CPU height task (if it is too high, it indicates that the CPU usage is relatively high. You can only make a rough estimation, not very accurate:
The entire ijpu code is relatively short. For details, refer to/* (c) Andrea giammarchi */(function (J, P, u) {var A = 'appendchild ', C = 'createelement', E = 'addeventlistener ', D = Document, L = "LOAD", W = Window; (function () {var I = setinterval (function (l) {L = 1; D = new date-D; If (D> 700) l ++; If (D> 650) l ++; If (D> 600) l ++; If (D> 550) l ++; S (j = L <j? -- J: l); D = new date}, 500), B = D. body, S = function () {I. classname = u + J}, I = d [c] ('P'), c = d [c] ('link'), D = new date; C. rel = 'stylesheet '; C. type = 'text/CSS '; C. href = P + u + '.css '; s (B [a] (c), B [a] (I);/* @ cc_on setinterval (function () {I. style. top = document. body. scrolltop + "PX"}, 50) @ */}) ()}) (5, 'HTTP: // www.3site. EU/JPU/', 'jpu ');