bench_bloc 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bench_bloc-0.1.0.gem +0 -0
- data/bench_bloc.gemspec +0 -1
- data/lib/bench_bloc.rb +47 -1
- data/lib/bench_bloc/version.rb +1 -1
- data/lib/tasks/bench.rake +83 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 55b6504674d2622b357441daca27585985d35ba9bed2ddae283b87342115a6eb
|
|
4
|
+
data.tar.gz: ae8fad42e481289c479ed59f759fc5baad493a90ea31ac41a3682a24d67a9def
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a40bbf1b230d04771c9653dfa38ce445687ee27b32eb96937e1cbad993565e794e1825e41439b0dbd062c70be2e6a24579250d1b747b27dd90a761c67e8d217c
|
|
7
|
+
data.tar.gz: 0e622168ab6dac7eaa33dd16e3f52632e9540dcfe0095d05fba12d23aa5aa3a1a77f476ab0bca5c778fb2577b6f3af399253a9e1ba6f282c7c0bbd7de0609dbc
|
|
Binary file
|
data/bench_bloc.gemspec
CHANGED
data/lib/bench_bloc.rb
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
require "bench_bloc/version"
|
|
2
|
+
require 'optparse'
|
|
2
3
|
|
|
3
4
|
module BenchBloc
|
|
4
5
|
class Error < StandardError; end
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
def log_results results, title
|
|
8
|
+
log = Logger.new("../log/benchmarks.log")
|
|
9
|
+
results.sort! { |a,b| b.real <=> a.real }
|
|
10
|
+
formatted_results = results.map { |res| format_result(res) }
|
|
11
|
+
header = "\n---\n\t#{title}\n"
|
|
12
|
+
summary = "\tTotal Time: #{summarize_real_time(results).round(2)} seconds\n\n"
|
|
13
|
+
log.info(header + summary + formatted_results.join("\n"))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def log_ruby_prof_results
|
|
17
|
+
# prof = RubyProf::Profile.new()
|
|
18
|
+
# prof.exclude_common_methods!
|
|
19
|
+
# validator = ValidationRules::TsValidatorService.new(ts)
|
|
20
|
+
# complex_rules = validator.get_complex_validation_rules
|
|
21
|
+
# binding.pry
|
|
22
|
+
# results = prof.profile { validator.run_complex_vr(complex_rules[0]) }
|
|
23
|
+
# log_prof_results results
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def summarize_real_time results
|
|
27
|
+
results.inject(0) do |agg, res|
|
|
28
|
+
agg + res.real
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def format_result result
|
|
33
|
+
"\t\t#{result.label}\n\t\t\t#{result.real.round(2)} seconds"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def bench_tasks
|
|
37
|
+
Rake.application.tasks.select do |task|
|
|
38
|
+
task.name.starts_with?("bench") &&
|
|
39
|
+
!task.name.ends_with?("_util") &&
|
|
40
|
+
task.name != "bench:all"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def option_parser
|
|
45
|
+
OptionParser.new do |opts|
|
|
46
|
+
opts.banner = "Usage: rake bench:* [options]"
|
|
47
|
+
opts.on("-r", "--ruby-prof", "Print a RubyProf report") do |rp|
|
|
48
|
+
@options[:ruby_prof] = rp
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
6
52
|
end
|
data/lib/bench_bloc/version.rb
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# TODO: Implement OptionsParser ie --rubyprof
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'pry'
|
|
4
|
+
require 'benchmark'
|
|
5
|
+
require "#{Rails.root}/benchmarks/bench_utils"
|
|
6
|
+
|
|
7
|
+
CONFIG_FILES=FileList['benchmarks/*.block.rb']
|
|
8
|
+
|
|
9
|
+
def put_namespace key, namespace
|
|
10
|
+
namespace key do
|
|
11
|
+
namespace.keys.each do |ns_key|
|
|
12
|
+
if is_task? namespace[ns_key]
|
|
13
|
+
put_task ns_key, namespace[ns_key]
|
|
14
|
+
else
|
|
15
|
+
put_namespace ns_key, namespace[ns_key]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# TODO: Add a ruby-prof method here if argument is passed
|
|
22
|
+
def put_task key, new_task
|
|
23
|
+
desc new_task[:desc]
|
|
24
|
+
task key => :environment do
|
|
25
|
+
to_profs = [new_task[:to_prof].call].flatten
|
|
26
|
+
results = Benchmark.bm do |x|
|
|
27
|
+
to_profs.each do |tp|
|
|
28
|
+
x.report(new_task[:label].call(tp)) do
|
|
29
|
+
new_task[:prof].call(tp)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
log_results results, "Benchmark Complex Validation Rules on Small Timesheet"
|
|
34
|
+
end
|
|
35
|
+
# format_ruby_prof(run_ruby_prof(new_task[:prof], tp)) if @options[:ruby_prof] == true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# def run_ruby_prof lam, args
|
|
39
|
+
# RubyProf.start
|
|
40
|
+
# lam.call args
|
|
41
|
+
# RubyProf.end
|
|
42
|
+
# end
|
|
43
|
+
|
|
44
|
+
# def format_ruby_prof res
|
|
45
|
+
# "Formatted Ruby Prof Results: #{res}"
|
|
46
|
+
# end
|
|
47
|
+
|
|
48
|
+
def is_task? obj
|
|
49
|
+
obj.keys.any?(:to_prof)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
CONFIG_FILES.each do |f|
|
|
53
|
+
config = eval File.read(f)
|
|
54
|
+
config.keys.each do |key|
|
|
55
|
+
namespace :bench do
|
|
56
|
+
put_namespace key, config[key]
|
|
57
|
+
desc "Options parser for bench tasks"
|
|
58
|
+
task parse_options_util: :environment do
|
|
59
|
+
@options = {}
|
|
60
|
+
option_parser.parse!
|
|
61
|
+
option_parser.parse!
|
|
62
|
+
end
|
|
63
|
+
desc "Clear Tests"
|
|
64
|
+
task clear_tests_util: :environment do
|
|
65
|
+
at_exit do
|
|
66
|
+
test_ts = Timesheet.where("general_remarks LIKE '%BENCHTEST%'")
|
|
67
|
+
puts "Clearing #{test_ts.count} test timesheets"
|
|
68
|
+
test_ts.destroy_all
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
desc "Run all benchmarks"
|
|
72
|
+
task all: :environment do
|
|
73
|
+
bench_tasks.each(&:execute)
|
|
74
|
+
Rake::Task["bench:clear_tests_util"].invoke
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
bench_tasks.each do |task|
|
|
81
|
+
Rake::Task[task.name]
|
|
82
|
+
.enhance(['bench:parse_options_util', 'bench:clear_tests_util'])
|
|
83
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bench_bloc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy
|
|
@@ -68,11 +68,13 @@ files:
|
|
|
68
68
|
- LICENSE.txt
|
|
69
69
|
- README.md
|
|
70
70
|
- Rakefile
|
|
71
|
+
- bench_bloc-0.1.0.gem
|
|
71
72
|
- bench_bloc.gemspec
|
|
72
73
|
- bin/console
|
|
73
74
|
- bin/setup
|
|
74
75
|
- lib/bench_bloc.rb
|
|
75
76
|
- lib/bench_bloc/version.rb
|
|
77
|
+
- lib/tasks/bench.rake
|
|
76
78
|
homepage: https://github.com/jdpaterson/bench_bloc
|
|
77
79
|
licenses:
|
|
78
80
|
- MIT
|