File: Rakefile

package info (click to toggle)
ruby-ref 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 268 kB
  • sloc: ruby: 1,262; java: 92; makefile: 5
file content (88 lines) | stat: -rw-r--r-- 2,241 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env rake

$:.push File.join(File.dirname(__FILE__), 'lib')

require 'ref'

begin
  require 'rspec'
  require 'rspec/core/rake_task'

  RSpec::Core::RakeTask.new(:spec) do |t|
    t.rspec_opts = '--color --backtrace --format documentation'
  end

  task :default => :spec
rescue LoadError
  puts 'Error loading Rspec rake tasks, probably building the gem...'
end

spec = eval(File.read(File.expand_path('../ref.gemspec', __FILE__)))

GEM_NAME       = 'ref'
EXTENSION_NAME = 'extension'
JAVA_EXT_NAME  = 'ref_ext'
CORE_GEMSPEC   = Gem::Specification.load('ref.gemspec')

if Ref.jruby?
  CORE_GEM = "#{GEM_NAME}-#{Ref::VERSION}-java.gem"

  require 'rake/javaextensiontask'
  Rake::JavaExtensionTask.new(JAVA_EXT_NAME, CORE_GEMSPEC) do |ext|
    ext.ext_dir = 'ext'
  end
else
  CORE_GEM = "#{GEM_NAME}-#{Ref::VERSION}.gem"
end

task :clean do
  rm_f Dir.glob('./**/*.so')
  rm_f Dir.glob('./**/*.bundle')
  rm_f Dir.glob('./lib/*.jar')
  mkdir_p 'pkg'
end

namespace :build do
  build_deps = [:clean]
  build_deps << :compile if Ref.jruby?
  desc "Build #{CORE_GEM} into the pkg directory"
  task :core => build_deps do
    sh "gem build #{CORE_GEMSPEC.name}.gemspec"
    sh 'mv *.gem pkg/'
  end
end

task :build => ['build:core']

namespace :test do
  namespace :performance do
    desc "Run a speed test on how long it takes to create 100000 weak references"
    task :weak_reference do
      puts "Testing performance of weak references..."
      unless Ref.jruby?
        t = Time.now
        Process.fork do
          100000.times do
            Ref::WeakReference.new(Object.new)
          end
        end
        Process.wait
        puts "Creating 100,000 weak references took #{Time.now - t} seconds"
      else
        puts 'Cannot run weak_reference performance test on JRuby - Fork is not available on this platform.'
      end
    end

    desc "Run a speed test on how long it takes to create 100000 soft references"
    task :soft_reference do
      puts "Testing performance of soft references..."
      t = Time.now
      100000.times do
        Ref::SoftReference.new(Object.new)
      end
      GC.start
      GC.start
      puts "Creating 100,000 soft references took #{Time.now - t} seconds"
    end
  end
end