diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-25 03:52:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-25 03:52:46 +0000 |
commit | 26143970c1300d09f9063ff77ba9b4d15472b9c8 (patch) | |
tree | c55dcca7c6efc1c0d1d38fd1cb6cfc8bfc815df2 /lib/rake | |
parent | 5940b1f6fc6745e4cb7516345a24b9b45567d21b (diff) | |
download | ruby-26143970c1300d09f9063ff77ba9b4d15472b9c8.tar.gz |
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
Diffstat (limited to 'lib/rake')
-rw-r--r-- | lib/rake/cpu_counter.rb | 12 |
1 files changed, 12 insertions, 0 deletions
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 |