Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 1.0.3
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 96 lines (78 sloc) 2.884 kb
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 89 90 91 92 93 94 95
require "rake"
require "rake/clean"
require 'rbconfig'

CLEAN.include %w'**/*.rbc *.core rdoc coverage'
RUBY=ENV['RUBY'] || File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])

desc "Build the RDoc documentation"
task :rdoc do
  require 'fileutils'
  FileUtils.rm_rf('rdoc')
  sh 'rdoc --quiet --line-numbers --inline-source --output rdoc --title ' \
     '"home_run: Fast Date/DateTime classes for ruby" --main README.rdoc ' \
     'README.rdoc CHANGELOG LICENSE lib/date.rb lib/date/format.rb ext/date_ext/*.c'
end

desc "Run the specs with mspec"
task :default => :spec
task :spec do
  ENV['RUBY'] ||= RUBY
  sh %{mspec}
end

desc "Build the gem"
task :gem => [:distclean] do
  sh %{gem build home_run.gemspec}
end

desc "Try to clean up everything"
task :distclean do
  CLEAN.concat(%w'pkg home_run-*.gem lib/1.* tmp')
  Rake::Task[:clean].invoke
end

begin
  require 'rake/extensiontask'
  Rake::ExtensionTask.new('date_ext')
rescue LoadError
end

desc "Regenerate the ragel parser"
task :parser do
  sh %{cd ext/date_ext && ragel date_parser.rl}
end

desc "Start an IRB shell using the extension"
task :irb do
  irb = ENV['IRB'] || File.join(RbConfig::CONFIG['bindir'], File.basename(RUBY).sub('ruby', 'irb'))
  sh %{#{irb} -I lib -r date}
end

desc "Run comparative benchmarks"
task :bench do
  sh %{#{RUBY} bench/cpu_bench.rb}
end

desc "Run all benchmarks"
task :bench_all => [:bench, :mem_bench, :garbage_bench]

desc "Run comparative parser benchmarks"
task :parser_bench do
  sh %{#{RUBY} bench/parser_bench.rb}
end

desc "Run comparative memory benchmarks"
task :mem_bench do
  if RUBY_PLATFORM =~ /mswin|mingw/
    puts "Memory benchmarks not supported on Windows"
    next
  end

  stdlib = `#{RUBY} -I #{RbConfig::CONFIG['rubylibdir']} bench/mem_bench.rb`.to_i
  home_run = `#{RUBY} -I lib bench/mem_bench.rb`.to_i
  puts "Date memory use,#{stdlib}KB,#{home_run}KB,#{sprintf('%0.1f', stdlib/home_run.to_f)}"

  stdlib = `#{RUBY} -I #{RbConfig::CONFIG['rubylibdir']} bench/dt_mem_bench.rb`.to_i
  home_run = `#{RUBY} -I lib bench/dt_mem_bench.rb`.to_i
  puts "DateTime memory use,#{stdlib}KB,#{home_run}KB,#{sprintf('%0.1f', stdlib/home_run.to_f)}"
end

desc "Run comparative garbage creation benchmarks"
task :garbage_bench do
  if RUBY_PLATFORM =~ /mswin|mingw/
    puts "Garbage creation benchmarks not supported on Windows"
    next
  end

  stdlib = `#{RUBY} -I #{RbConfig::CONFIG['rubylibdir']} bench/garbage_bench.rb`.to_i
  home_run = `#{RUBY} -I lib bench/garbage_bench.rb`.to_i
  puts "Date garbage created,#{stdlib}KB,#{home_run}KB,#{sprintf('%0.1f', stdlib/home_run.to_f)}"

  stdlib = `#{RUBY} -I #{RbConfig::CONFIG['rubylibdir']} bench/dt_garbage_bench.rb`.to_i
  home_run = `#{RUBY} -I lib bench/dt_garbage_bench.rb`.to_i
  puts "DateTime garbage created,#{stdlib}KB,#{home_run}KB,#{sprintf('%0.1f', stdlib/home_run.to_f)}"
end
Something went wrong with that request. Please try again.