Get CPU/GPU/memory information

前端 未结 3 554
太阳男子
太阳男子 2020-12-04 15:45

I need to get any information about the CPU/GPU/memory.The number of cores, memory value, memory and cpu usage... I found a way to do this for IE:How to Use JavaScript to Fi

相关标签:
3条回答
  • 2020-12-04 16:19

    Currently Chrome Canary supports returning the amount of CPU cores using:

    navigator.hardwareConcurrency
    

    This worked for me in Chrome Canary 37.

    0 讨论(0)
  • 2020-12-04 16:19

    I wrote this quick script to get the cpu speed:

    var _speedconstant = 8.9997e-9; //if speed=(c*a)/t, then constant=(s*t)/a and time=(a*c)/s
    var d = new Date();
    var amount = 150000000;
    var estprocessor = 1.7; //average processor speed, in GHZ
    console.log("JSBenchmark by Aaron Becker, running loop "+amount+" times.     Estimated time (for "+estprocessor+"ghz processor) is "+(Math.round(((_speedconstant*amount)/estprocessor)*100)/100)+"s");
    for (var i = amount; i>0; i--) {} 
    var newd = new Date();
    var accnewd = Number(String(newd.getSeconds())+"."+String(newd.getMilliseconds()));
    var accd = Number(String(d.getSeconds())+"."+String(d.getMilliseconds())); 
    var di = accnewd-accd;
    //console.log(accnewd,accd,di);
    if (d.getMinutes() != newd.getMinutes()) {
    di = (60*(newd.getMinutes()-d.getMinutes()))+di}
    spd = ((_speedconstant*amount)/di);
    console.log("Time: "+Math.round(di*1000)/1000+"s, estimated speed: "+Math.round(spd*1000)/1000+"GHZ");
    

    Note that this depends on browser tabs, memory use, etc. but I found it pretty accurate if you only run it once, say at the loading of a page.

    This may not be accurate for desktop devices, especially PCs, but I use it in my website only when other solutions like the first one fail, for getting the average speed of mobile devices (allows me to estimate cores used) using only client-side JS. It may not be the best, but it does pretty well.

    If you would like you can change the _speedconstant to change the speed, just calculate it with the equation (knowncpuspeed*knowntimetocomplete)/knowncycles. Hope you find this useful!


    UPDATE 10/19/17: Changed _speedconstant for the new chrome V8 JS engine and added section about what I use it for.

    0 讨论(0)
  • 2020-12-04 16:25

    This code will print GPU infos an will list all info you can have with the performance object of this browser (there is no standard for the BOM so it changes for each browser).

    <html>
    
    <body>
      <canvas id="glcanvas" width="0" height="0"></canvas>
      <script>
        var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
    
        document.write("<br>");
        for (var value in performance) {
          document.write(value + "<br>");
        }
    
        document.write("<br><br><br>");
    
        var canvas;
        canvas = document.getElementById("glcanvas");
        var gl = canvas.getContext("experimental-webgl");
    
        document.write(gl.getParameter(gl.RENDERER) + "<br>");
        document.write(gl.getParameter(gl.VENDOR) + "<br>");
        document.write(getUnmaskedInfo(gl).vendor + "<br>");
        document.write(getUnmaskedInfo(gl).renderer + "<br>");
    
    
        function getUnmaskedInfo(gl) {
          var unMaskedInfo = {
            renderer: '',
            vendor: ''
          };
    
          var dbgRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
          if (dbgRenderInfo != null) {
            unMaskedInfo.renderer = gl.getParameter(dbgRenderInfo.UNMASKED_RENDERER_WEBGL);
            unMaskedInfo.vendor = gl.getParameter(dbgRenderInfo.UNMASKED_VENDOR_WEBGL);
          }
    
          return unMaskedInfo;
        }
      </script>
    </body>

    Output in Chrome :

    onresourcetimingbufferfull
    onwebkitresourcetimingbufferfull
    timing
    navigation
    memory
    now
    getEntries
    getEntriesByType
    getEntriesByName
    clearResourceTimings
    setResourceTimingBufferSize
    webkitClearResourceTimings
    webkitSetResourceTimingBufferSize
    mark
    clearMarks
    measure
    clearMeasures
    addEventListener
    removeEventListener
    dispatchEvent
    
    
    
    WebKit WebGL
    WebKit
    NVIDIA Corporation
    NVIDIA GeForce GTX 775M OpenGL Engine
    

    Output in Firfox :

    now
    getEntries
    getEntriesByType
    getEntriesByName
    clearResourceTimings
    setResourceTimingBufferSize
    mark
    clearMarks
    measure
    clearMeasures
    toJSON
    timing
    navigation
    onresourcetimingbufferfull
    
    
    
    Mozilla
    Mozilla
    

    Output in Safari :

    navigation
    timing
    now
    
    
    
    WebKit WebGL
    WebKit
    NVIDIA Corporation
    NVIDIA GeForce GTX 775M OpenGL Engine
    
    0 讨论(0)
提交回复
热议问题