WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

14
node_modules/physical-cpu-count/.gitlab-ci.yml generated vendored Normal file
View File

@ -0,0 +1,14 @@
cache:
paths:
- node_modules
argon:
image: node:argon
script:
- npm i
- npm t
boron:
image: node:boron
script:
- npm it

1
node_modules/physical-cpu-count/.npmignore generated vendored Normal file
View File

@ -0,0 +1 @@
test.js

31
node_modules/physical-cpu-count/README.md generated vendored Normal file
View File

@ -0,0 +1,31 @@
# physical-cpu-count
Returns the number of physical CPU cores.
## Example
```js
const physicalCpuCount = require('physical-cpu-count')
// 4
const logicalCpuCount = require('os').cpus().length
// 8
```
## Use Case
Working with clusters of Node.js processes it is common to see code using `os.cpus().length` as the number of child workers to fork. For some workloads this can negatively impact performance on CPUs that use simultaneous multithreading (SMT). Latency is doubled because two processes share the same physical CPU core to get their work done. Additionally there is memory spent for each running worker, as well as time to spawn their processes. It is better to fork no more child processes than there are physical cores.
## Known Limitations
Implemented for Linux, macOS, and Windows.
Other platforms use a naive approach that only looks at Intel CPUs, and assumes every Intel CPU supports, and has enabled, Hyper-Threading with two threads per physical core. These assumptions are not always correct.
Power management might also make CPU cores unavailable.
## See also:
- [Issue `nodejs/node#7730` to implement physical core detection natively in Node.js.](https://github.com/nodejs/node/issues/7730)
- [Relevant Stack Overflow answer for macOS and Linux.](https://stackoverflow.com/a/23378780)
- [Solutions for Windows WMIC from the command prompt.](http://superuser.com/questions/226552/how-to-tell-how-many-cpus-cores-you-have-on-windows-7)

35
node_modules/physical-cpu-count/index.js generated vendored Normal file
View File

@ -0,0 +1,35 @@
'use strict'
const os = require('os')
const childProcess = require('child_process')
function exec (command) {
const output = childProcess.execSync(command, {encoding: 'utf8'})
return output
}
let amount
const platform = os.platform()
if (platform === 'linux') {
const output = exec('lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l')
amount = parseInt(output.trim(), 10)
} else if (platform === 'darwin') {
const output = exec('sysctl -n hw.physicalcpu_max')
amount = parseInt(output.trim(), 10)
} else if (platform === 'windows') {
const output = exec('WMIC CPU Get NumberOfCores')
amount = output.split(os.EOL)
.map(function parse (line) { return parseInt(line) })
.filter(function numbers (value) { return !isNaN(value) })
.reduce(function add (sum, number) { return sum + number }, 0)
} else {
const cores = os.cpus().filter(function (cpu, index) {
const hasHyperthreading = cpu.model.includes('Intel')
const isOdd = index % 2 === 1
return !hasHyperthreading || isOdd
})
amount = cores.length
}
module.exports = amount

51
node_modules/physical-cpu-count/package.json generated vendored Normal file
View File

@ -0,0 +1,51 @@
{
"_from": "physical-cpu-count@^2.0.0",
"_id": "physical-cpu-count@2.0.0",
"_inBundle": false,
"_integrity": "sha1-GN4vl+S/epVRrXURlCtUlverpmA=",
"_location": "/physical-cpu-count",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "physical-cpu-count@^2.0.0",
"name": "physical-cpu-count",
"escapedName": "physical-cpu-count",
"rawSpec": "^2.0.0",
"saveSpec": null,
"fetchSpec": "^2.0.0"
},
"_requiredBy": [
"/gatsby"
],
"_resolved": "https://registry.npmjs.org/physical-cpu-count/-/physical-cpu-count-2.0.0.tgz",
"_shasum": "18de2f97e4bf7a9551ad7511942b5496f7aba660",
"_spec": "physical-cpu-count@^2.0.0",
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/gatsby",
"author": {
"name": "Sebastiaan Deckers",
"email": "sebdeckers83@gmail.com"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Provides the number of physical cores",
"devDependencies": {
"snazzy": "^5.0.0"
},
"keywords": [
"os",
"cpu",
"cpus",
"length",
"physical",
"logical",
"cores"
],
"license": "ISC",
"main": "index.js",
"name": "physical-cpu-count",
"scripts": {
"test": "snazzy && node test.js"
},
"version": "2.0.0"
}