41

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 Find Hardware Information

solutions for other browsers I do not know. Any idea how to do it? maybe webgl has access to information about your computer? or flash? or any other technology?

Thank you very much

Nickolay
  • 28,261
  • 8
  • 94
  • 160
Alex Nester
  • 411
  • 1
  • 4
  • 3
  • 1
    In google chrome you can use console.memory to find out the amount of memory available in the JS heap. – Benjamin Gruenbaum Mar 17 '13 at 19:01
  • I'd have a look at whether a Flash shim might help. I haven't seen any cross-browser API for hardware info before. – Drew Noakes Mar 17 '13 at 19:02
  • Those methods no longer work in IE. Browsers are trying to make it harder to track people. One way to track people is to look up all the info about their machine. That plus their ip address is often enough to identify someone or a least a specific machine. So, browser don't show CPU/GPU/Memory/# cores/etc. (https://panopticlick.eff.org/) – gman Mar 18 '13 at 15:32

3 Answers3

29

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
Sam Denty
  • 3,024
  • 3
  • 19
  • 33
Thomas
  • 435
  • 5
  • 9
  • 4
    I really appreciate the no-IE thing, anyway, why should we wonder about a browser with less than 10% worldwide market-share.... Vote+1 – Ant Sep 20 '16 at 15:45
13

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

navigator.hardwareConcurrency

This worked for me in Chrome Canary 37.

Bas van Dijk
  • 7,931
  • 8
  • 51
  • 81
  • Works in Chrome 40 stable. – cprcrack Feb 02 '15 at 23:47
  • I wrote about hardwareConcurrency in other browsers here: http://stackoverflow.com/a/31896597/1026 – Nickolay Aug 08 '15 at 17:30
  • 1
    Is this cores or threads? Because when I did this I got the number 4 back, but my processor only has two cores (it does have 4 threads though). I'm guessing this is because I have an [i7](http://ark.intel.com/products/64893/Intel-Core-i7-3520M-Processor-4M-Cache-up-to-3_60-GHz)? – Hanna Aug 31 '15 at 19:31
  • According to https://wiki.whatwg.org/wiki/Navigator_HW_Concurrency it returns the number of logical processors available to the user agent, up to an optional thread limit per origin. – Bas van Dijk Sep 01 '15 at 11:40
  • 2
    @Johannes with processors supporting Hyperthreading the system sees your double core processor as quad core. Not browsers only, but OS itself. – GuardianX Aug 11 '16 at 11:36
  • Also implemented in firefox as of now. – r3wt Jan 07 '17 at 02:43
7

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.

Aaron Becker
  • 431
  • 6
  • 8
  • Well.. I guess it's accurate if you tweak the `_speedconstant` for "your" machine, because running this in my 4-year-old machine estimates 23.753GHz. This is also susceptible to javascript engine optimizations. – olivarra1 Oct 18 '17 at 18:16
  • 1
    @olivarra1 Yep, it is not the most reliable, but I found that it is good for a quick client-side approximate estimate of CPU speed, for mobile devices especially. I have used it in the past when other solutions like the first one fail, or when the browser cannot be identified. I can see your point though, it doesn't really work on PCs with JS optimizations or multiple cores :) – Aaron Becker Oct 20 '17 at 03:47
  • 1
    Yes, that's definitely better than nothing.... I will consider the output of this method as a generic "JS speed value" more than the GHz of the processor, which is more than enough to optimize the app to the power of the machine. – olivarra1 Oct 20 '17 at 08:02
  • @olivarra1 Good idea :) – Aaron Becker Oct 23 '17 at 01:12
  • Tried this script on Intel Core i7 iMac (late 2013) model at 3.1GHz, it reports 7.7GHz... seems quite inaccurate. – Raptor Jan 23 '18 at 06:25
  • We used this technic in 1999, when my computer had < 100Mhz and a for loop with 10000 empty iterations took 1 second. – Daniel W. Dec 13 '18 at 17:02