Sha256: 6de54d0fef07582f92b4fbd07204591014397e2374ae1f70da8a735063d7fe07

Contents?: true

Size: 857 Bytes

Versions: 6

Compression:

Stored size: 857 Bytes

Contents

require 'shellwords'

class ImageOptim
  module Util
    # http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed
    def self.processor_count
      @processor_count ||= case host_os = RbConfig::CONFIG['host_os']
      when /darwin9/
        `hwprefs cpu_count`
      when /darwin/
        (`which hwprefs` != '') ? `hwprefs thread_count` : `sysctl -n hw.ncpu`
      when /linux/
        `grep -c processor /proc/cpuinfo`
      when /freebsd/
        `sysctl -n hw.ncpu`
      when /mswin|mingw/
        require 'win32ole'
        wmi = WIN32OLE.connect('winmgmts://')
        cpu = wmi.ExecQuery('select NumberOfLogicalProcessors from Win32_Processor')
        cpu.to_enum.first.NumberOfLogicalProcessors
      else
        warn "Unknown architecture (#{host_os}) assuming one processor."
        1
      end.to_i
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
image_optim-0.6.0 lib/image_optim/util.rb
image_optim-0.5.1 lib/image_optim/util.rb
image_optim-0.5.0 lib/image_optim/util.rb
image_optim-0.4.2 lib/image_optim/util.rb
image_optim-0.4.1 lib/image_optim/util.rb
image_optim-0.4.0 lib/image_optim/util.rb