forked from janlelis/paint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
116 lines (97 loc) · 2.3 KB
/
Rakefile
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
GEMSPEC = 'paint.gemspec'
require 'rake'
#require 'rake/rdoctask'
require 'fileutils'
require 'rspec/core/rake_task'
task :default => :spec
task :test => :spec
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = [
'--color',
'-r ' + File.expand_path( File.join( 'spec', 'spec_helper') ),
]
end
def gemspec
@gemspec ||= eval(File.read(GEMSPEC), binding, GEMSPEC)
end
desc "Build the gem"
task :gem => :gemspec do
sh "gem build #{GEMSPEC}"
FileUtils.mkdir_p 'pkg'
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
end
desc "Install the gem locally"
task :install => :gem do
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
end
desc "Generate the gemspec"
task :generate do
puts gemspec.to_ruby
end
desc "Validate the gemspec"
task :gemspec do
gemspec.validate
end
#Rake::RDocTask.new do |rdoc|
# require File.expand_path( File.join( 'lib', 'paint') )
#
# rdoc.rdoc_dir = 'doc'
# rdoc.title = "paint #{Paint::VERSION}"
# rdoc.rdoc_files.include('README*')
# rdoc.rdoc_files.include('lib/**/*.rb')
#end
desc "Run a Benchmark"
task :benchmark do
require 'benchmark'
require 'term/ansicolor'
class String
include Term::ANSIColor
end
require 'rainbow'
$:.unshift '../lib'
require 'paint'
n = 100_000
colors = [:black, :red, :green, :yellow, :blue, :magenta, :cyan]
def colors.next
@index ||= 0
at((@index += 1) % size)
end
Benchmark.bmbm 30 do |results|
string = 'Ruby is awesome!'
results.report 'cycle' do
n.times do
colors.next
end
end
results.report 'paint' do
n.times do
Paint[string, colors.next]
end
end
results.report 'term-ansicolor' do
n.times do
string.send(colors.next)
end
end
results.report 'rainbow' do
n.times do
string.color(colors.next)
end
end
results.report 'paint with background' do
n.times do
Paint[string, colors.next, colors.next]
end
end
results.report 'term-ansicolor with background' do
n.times do
string.send(colors.next).send("on_#{colors.next}")
end
end
results.report 'rainbow with background' do
n.times do
string.color(colors.next).background(colors.next)
end
end
end
end