Reputation: 551
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
Upvotes: 55
Views: 81451
Reputation: 659
Estimate CPU speed by timing how long it takes to decrement a variable millions of times:
const runs = 150000000;
const start = performance.now(); // in ms, usually with 100us resolution
for (let i = runs; i>0; i--) {}
const end = performance.now();
const ms = end - start;
const cyclesPerRun = 2;
const speed = (runs / ms / 1000000) * cyclesPerRun;
console.log(`Time: ${Math.round(ms)/1000}s, estimated speed: ${Math.round(speed*10)/10} GHz`);
* cyclesPerRun
is a very rough way to map "subtractions per second" to clock speed and it varies a lot across browsers (because their JavaScript engines might optimize the code differently) and CPUs (because they might be able to pipeline more instructions, they might ramp up their frequency faster, etc.). You might be better off just using runs / ms
as a generic "CPU speed" parameter instead of trying to estimate the clock speed in GHz with cyclesPerRun
.
You can also estimate cyclesPerRun
yourself by running the code above on a CPU you know the clock speed of and then doing this:
const knownSpeed = 3.2; // GHz
const estimatedCyclesPerRun = knownSpeed / (runs/ms/1000000);
console.log("cyclesPerRun = " + estimatedCyclesPerRun);
Also this benchmark depends on the number of browser tabs the user has open or if some other program (like a video game) is already using the computer's resources, etc.
Upvotes: 12
Reputation: 613
This code will print GPU info and will list all info you can get from the Performance
object of this browser (it's different for each browser).
<html>
<body>
<canvas id="glcanvas" width="0" height="0"></canvas>
<script>
var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
const performanceKeys = [];
for (var value in performance) {
performanceKeys.push(value);
}
document.write("<br>");
document.write(performanceKeys.sort().map((p) => '<a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance/' + p + '">' + p + "</a>").join("<br>"));
document.write("<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:
addEventListener
clearMarks
clearMeasures
clearResourceTimings
dispatchEvent
eventCounts
getEntries
getEntriesByName
getEntriesByType
mark
measure
memory
navigation
now
onresourcetimingbufferfull
removeEventListener
setResourceTimingBufferSize
timeOrigin
timing
toJSON
WebKit WebGL
WebKit
NVIDIA Corporation
NVIDIA GeForce GTX 775M OpenGL Engine
Output in Firefox:
addEventListener
clearMarks
clearMeasures
clearResourceTimings
dispatchEvent
eventCounts
getEntries
getEntriesByName
getEntriesByType
mark
measure
navigation
now
onresourcetimingbufferfull
removeEventListener
setResourceTimingBufferSize
timeOrigin
timing
toJSON
Mozilla
Mozilla
Output in Safari:
addEventListener
clearMarks
clearMeasures
clearResourceTimings
dispatchEvent
getEntries
getEntriesByName
getEntriesByType
mark
measure
navigation
now
onresourcetimingbufferfull
removeEventListener
setResourceTimingBufferSize
timeOrigin
timing
toJSON
WebKit WebGL
WebKit
NVIDIA Corporation
NVIDIA GeForce GTX 775M OpenGL Engine
Upvotes: 39
Reputation: 10713
Currently Chrome Canary supports returning the amount of CPU cores using:
navigator.hardwareConcurrency
This worked for me in Chrome Canary 37.
Upvotes: 15