crystal-lang


How to detect number of CPU cores in Crystal?


How do you detect the number of CPU cores in crystal?
In Go you can do runtime.NumCPU() and in Node.js you can do os.cpus(). Is there something similar in Crystal?
The last time I checked (admittedly that was long ago) there was no direct way to do that, but you can get access to this information through the command line. I ended up combining multiple of these answers for redundancy.
THREADS = `getconf _NPROCESSORS_ONLN || nproc --all || grep -c '^processor' /proc/cpuinfo`.to_i

Related Links

Condition over object's type
Crystal C bindings: argument const unsigned char **
Crystal C bindings: return type char*
Make Class member attribute of type Array(T) accept 2D arrays of T
JSON.mapping if “root” attribute has inherit keys
Crystal C bindings: using fopen
Define Class object validations
Set attribute of type “Class” to define it as Int32, String, Float64
Set both default attribute and type of attribute
How can I test private methods?
Write binary data to stdout in Crystal
Unable to compile after upgrade from crystal 0.19.4 to 0.20
Application server for Crystal web app / Kemal
Crystal Fiber error - “Unhandled exception in spawn: SSL_shutdown: Operation now in progress (Errno)”
Convert hex string to int in Crystal
Crystal convert string to hash from response.body

Categories

HOME
embedded
phpword
microsoftgraph
paraview
forms
redux-form
phpmyadmin
ns-3
zend-framework
yahoo-finance
sitecore
knitr
appcelerator
alarm
scripting
nested-if
odoo-8
barcode
joomla3.0
dkim
vimdiff
ibeacon-android
spring-social
bitnami
linear-algebra
feathersjs
google-content-api
boost-icl
rubymotion
jquery-callback
direct3d11
moses
gpio
jackson-modules
has-and-belongs-to-many
entity-relationship-model
rpgle
browser-sync
event-flow
powershell-ise
cart
clickjacking
papaparse
twos-complement
indy10
yowsup
engine.io
sim-toolkit
xcode7.3
softmax
outputcache
placeholder
uiimage
monkey-testing
openresty
rserve
compiler-design
backbone-collections
baidu
sandcastle
choice
taocp
spring-cloud-feign
watch-os-2
gogs
xdoclet
google-query-language
nservicebus5
mediametadataretriever
ellucian-scribe
vhosts
ess
text-search
sql-server-data-tools
jsvc
actionfilterattribute
grouping-sets
document-repository
ejb-2.x
gae-quotas
accesscontrolexception
embedded-fonts
c++builder-xe5
dtmf
superscrollorama
fb.ui
monotouch.dialog
vfs
veracity
google-maps-mobile
android-holo-everywhere
winmain
webdev.webserver
lr
socketserver
objective-j
ie-compatibility-mode
instantiationexception
movieplayer

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App