-
Notifications
You must be signed in to change notification settings - Fork 13
/
Rakefile
102 lines (86 loc) · 2.2 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
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
task default: :test
namespace :benchmark do
task :speed do
require "bundler/setup"
Bundler.require
require "benchmark/ips"
require "stringio"
str = StringIO.new
logger = ::Logger.new(str)
str2 = StringIO.new
logger2 = ::Logger.new(str2)
Logstop.guard(logger2)
Benchmark.ips do |x|
x.report "logger" do
logger.info "This is a string"
end
x.report "logger2" do
logger2.info "This is a string"
end
end
end
task :memory do
require "bundler/setup"
Bundler.require
require "memory_profiler"
require "stringio"
str = StringIO.new
logger = ::Logger.new(str)
str2 = StringIO.new
logger2 = ::Logger.new(str2)
Logstop.guard(logger2)
print_options = {
detailed_report: false,
allocated_strings: 0,
retained_strings: 0
}
report = MemoryProfiler.report do
1000.times do
logger.info "This is a string"
end
end
puts "No Logstop"
report.pretty_print(print_options)
report = MemoryProfiler.report do
1000.times do
logger2.info "This is a string"
end
end
puts "Logstop"
report.pretty_print(print_options)
end
task :regexp do
require "bundler/setup"
Bundler.require
require "benchmark/ips"
require "stringio"
msg = "I, [2018-12-10T14:49:12.209047 #56045] INFO -- : This is a string"
Benchmark.ips do |x|
x.report "credit card" do
msg.gsub(Logstop::CREDIT_CARD_REGEX, Logstop::FILTERED_STR)
end
x.report "email" do
msg.gsub(Logstop::EMAIL_REGEX, Logstop::FILTERED_STR)
end
x.report "ip" do
msg.gsub(Logstop::IP_REGEX, Logstop::FILTERED_STR)
end
x.report "phone" do
msg.gsub(Logstop::PHONE_REGEX, Logstop::FILTERED_STR)
end
x.report "ssn" do
msg.gsub(Logstop::SSN_REGEX, Logstop::FILTERED_STR)
end
x.report "url password" do
msg.gsub(Logstop::URL_PASSWORD_REGEX, Logstop::FILTERED_URL_STR)
end
end
end
end