def self.cpu_count
@cpu_count ||=
case RUBY_PLATFORM
when /darwin9/
`hwprefs cpu_count`.to_i
when /darwin10/
(hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
when /linux/
`cat /proc/cpuinfo | grep processor | wc -l`.to_i
when /freebsd/
`sysctl -n hw.ncpu`.to_i
else
if RbConfig::CONFIG['host_os'] =~ /darwin/
(hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
elsif self.windows?
require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor")
cpu.to_enum.first.NumberOfCores
else
raise 'unknown platform processor_count'
end
end
end