From 26143970c1300d09f9063ff77ba9b4d15472b9c8 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 25 Oct 2014 03:52:46 +0000 Subject: rake/cpu_counter.rb: use Etc.nprocessors * lib/rake/cpu_counter.rb (count): prefer Etc.nprocessors, which is hundreds times faster. * test/rake/test_rake_cpu_counter.rb: add tests for features, and remove useless tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rake/cpu_counter.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/rake/cpu_counter.rb b/lib/rake/cpu_counter.rb index d7c92a6cbe..6d0b878b19 100644 --- a/lib/rake/cpu_counter.rb +++ b/lib/rake/cpu_counter.rb @@ -44,6 +44,18 @@ module Rake end end + begin + require 'etc' + rescue LoadError + else + if Etc.respond_to?(:nprocessors) + undef count + def count + return Etc.nprocessors + end + end + end + def count_via_java_runtime Java::Java.lang.Runtime.getRuntime.availableProcessors rescue StandardError -- cgit v1.2.3