forked from aquasync/ruby-ole
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
85 lines (73 loc) · 1.95 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
require 'rubygems'
require 'rake/rdoctask'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rbconfig'
require 'fileutils'
spec = eval File.read('ruby-ole.gemspec')
task :default => [:test]
Rake::TestTask.new do |t|
t.test_files = FileList["test/test_*.rb"]
t.warning = true
t.verbose = true
end
begin
require 'rcov/rcovtask'
# NOTE: this will not do anything until you add some tests
desc "Create a cross-referenced code coverage report"
Rcov::RcovTask.new do |t|
t.test_files = FileList['test/test*.rb']
t.ruby_opts << "-Ilib" # in order to use this rcov
t.rcov_opts << "--xrefs" # comment to disable cross-references
t.verbose = true
end
rescue LoadError
# Rcov not available
end
Rake::RDocTask.new do |t|
t.rdoc_dir = 'doc'
t.rdoc_files.include 'lib/**/*.rb'
t.rdoc_files.include 'README', 'ChangeLog'
t.title = "#{PKG_NAME} documentation"
t.options += %w[--line-numbers --inline-source --tab-width 2]
t.main = 'README'
end
Rake::GemPackageTask.new(spec) do |t|
t.gem_spec = spec
t.need_tar = true
t.need_zip = false
t.package_dir = 'build'
end
desc 'Run various benchmarks'
task :benchmark do
require 'benchmark'
require 'tempfile'
require 'ole/storage'
# should probably add some read benchmarks too
def write_benchmark opts={}
files, size = opts[:files], opts[:size]
block_size = opts[:block_size] || 100_000
block = 0.chr * block_size
blocks, remaining = size.divmod block_size
remaining = 0.chr * remaining
Tempfile.open 'ole_storage_benchmark' do |temp|
Ole::Storage.open temp do |ole|
files.times do |i|
ole.file.open "file_#{i}", 'w' do |f|
blocks.times { f.write block }
f.write remaining
end
end
end
end
end
Benchmark.bm do |bm|
bm.report 'write_1mb_1x5' do
5.times { write_benchmark :files => 1, :size => 1_000_000 }
end
bm.report 'write_1mb_2x5' do
5.times { write_benchmark :files => 1_000, :size => 1_000 }
end
end
end