Gathering detailed insights and metrics for detect-gpu-js
Gathering detailed insights and metrics for detect-gpu-js
npm install detect-gpu-js
Typescript
Module System
Node Version
NPM Version
78.1
Supply Chain
99.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
JavaScript (97.95%)
HTML (2.05%)
Total Downloads
16,383
Last Day
20
Last Week
66
Last Month
525
Last Year
15,516
4 Stars
31 Commits
5 Watching
1 Branches
Latest Version
1.0.7
Package Id
detect-gpu-js@1.0.7
Unpacked Size
1.35 MB
Size
198.44 kB
File Count
25
NPM Version
10.1.0
Node Version
20.8.1
Publised On
25 Nov 2023
Cumulative downloads
Total Downloads
Last day
300%
20
Compared to previous day
Last week
11.9%
66
Compared to previous week
Last month
-7.7%
525
Compared to previous month
Last year
1,689.6%
15,516
Compared to previous year
1
19
Detect and rate GPUs based on their 3D rendering benchmark score allowing the developer to provide sensible default settings for graphically intensive applications. Think of it like a user-agent detection for the GPU but more powerful.
This project is a maintained fork of detect-gpu project rewritten in JavaScript.
Make sure you have Node.js installed, then:
1 $ npm install detect-gpu-js
By default we use the UNPKG CDN to host the benchmark data. If you would like to serve the benchmark data yourself, download the required benchmarking data from benchmarks.tar.gz and serve it from a public directory.
Alternatively, there is the detect-gpu.bundle.js
build that comes with benchmark data embedded. This however requires 300KB+ more data downloaded over the network.
1import { getGPUTier } from 'detect-gpu'; 2 3(async () => { 4 const gpuTier = await getGPUTier(); 5 6 // Example output: 7 // { 8 // "tier": 1, 9 // "isMobile": false, 10 // "type": "BENCHMARK", 11 // "fps": 21, 12 // "gpu": "intel iris graphics 6100" 13 // } 14})();
detect-gpu-js
uses rendering benchmark scores (framerate, normalized by resolution) in order to determine what tier should be assigned to the user's GPU. If no WebGLContext
can be created, the GPU is blocklisted or the GPU has reported to render on less than 15 fps
tier: 0
is assigned. One should provide a fallback to a non-WebGL experience.
Based on the reported fps
the GPU is then classified into either tier: 1 (>= 15 fps)
, tier: 2 (>= 30 fps)
or tier: 3 (>= 60 fps)
. The higher the tier the more graphically intensive workload you can offer to the user.
1getGPUTier({
2 /**
3 * URL of directory where benchmark data is hosted.
4 *
5 * @default https://unpkg.com/detect-gpu-js@{version}/dist/benchmarks
6 */
7 benchmarksURL,
8 /**
9 * Optionally pass in a WebGL context to avoid creating a temporary one
10 * internally.
11 */
12 glContext,
13 /**
14 * Whether to fail if the system performance is low or if no hardware GPU is
15 * available.
16 *
17 * @default false
18 */
19 failIfMajorPerformanceCaveat,
20 /**
21 * Framerate per tier for mobile devices.
22 *
23 * @defaultValue [0, 15, 30, 60]
24 */
25 mobileTiers,
26 /**
27 * Framerate per tier for desktop devices.
28 *
29 * @defaultValue [0, 15, 30, 60]
30 */
31 desktopTiers,
32 /**
33 * Use HiDPI (Retina) resolution to find benchmark results.
34 *
35 * @defaultValue true
36 */
37 hidpiScreenSize,
38 /**
39 * Optionally override specific parameters. Used mainly for testing.
40 */
41 override: {
42 renderer,
43 /**
44 * Override whether device is an iPad.
45 */
46 isIpad,
47 /**
48 * Override whether device is a mobile device.
49 */
50 isMobile,
51 /**
52 * Override device screen size.
53 */
54 screenSize: { width, height },
55 /**
56 * Override how benchmark data is loaded.
57 */
58 loadBenchmarks
59 };
60})
Requires JavaScript modules to be supported, e.g. works on Chrome 61+, Firefox 60+, Safari 11+ (most versions dated back to 2017).
The project is released under the MIT license.
detect-gpu-js
uses both mobile and desktop benchmarking scores from https://gfxbench.com.
No vulnerabilities found.
No security vulnerabilities found.