Skip to content

Commit aab6613

Browse files
committed
Remove erb, convert vm1/vm2
1 parent d4e0d19 commit aab6613

File tree

1 file changed

+78
-4
lines changed

1 file changed

+78
-4
lines changed

lib/tasks/temporary/oneshot.rake

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ namespace :oneshot do
132132
end
133133
end
134134

135-
desc 'Remove invalid meteor'
136-
task remove_meteor: :environment do
135+
desc 'Remove invalid erb'
136+
task remove_erb: :environment do
137137
time_result_type = BenchmarkResultType.find_by!(name: 'Execution time', unit: 'Seconds')
138138
ips_result_type = BenchmarkResultType.find_by!(name: 'Iteration per second', unit: 'i/s')
139139

140-
BenchmarkType.where(category: 'so_meteor_contest').each do |benchmark_type|
141-
unless benchmark_type.script_url.match(%r[\Ahttps://raw\.githubusercontent\.com/ruby-bench/ruby-bench-suite/master/ruby/benchmark/.+\.rb\z])
140+
BenchmarkType.where(category: ['app_erb', 'erb_render']).each do |benchmark_type|
141+
unless benchmark_type.script_url.match(%r[\Ahttps://raw\.githubusercontent\.com/ruby-bench/ruby-bench-suite/master/ruby/benchmark/.+\.yml\z])
142142
next
143143
end
144144

@@ -149,4 +149,78 @@ namespace :oneshot do
149149
original_type.benchmark_runs.where(benchmark_result_type: time_result_type).delete_all
150150
end
151151
end
152+
153+
desc 'Convert vm1 to ips'
154+
task vm1: :environment do
155+
time_result_type = BenchmarkResultType.find_by!(name: 'Execution time', unit: 'Seconds')
156+
ips_result_type = BenchmarkResultType.find_by!(name: 'Iteration per second', unit: 'i/s')
157+
158+
BenchmarkType.all.each do |benchmark_type|
159+
unless benchmark_type.script_url.match(%r[\Ahttps://raw\.githubusercontent\.com/ruby-bench/ruby-bench-suite/master/ruby/benchmark/vm1_.+\.yml\z])
160+
next
161+
end
162+
163+
original_type = BenchmarkType.where.not(id: benchmark_type.id).find_by(category: benchmark_type.category)
164+
if original_type.nil? || !original_type.script_url.match(%r[\Ahttps://raw.githubusercontent.com/ruby-bench/ruby-bench-suite/master/ruby/benchmarks/bm_])
165+
next
166+
end
167+
168+
print "benchmark_type: #{benchmark_type.category}"
169+
original_type.benchmark_runs.where(benchmark_result_type: time_result_type).find_in_batches do |benchmark_runs|
170+
benchmark_runs.each do |benchmark_run|
171+
result = {}
172+
benchmark_run.result.each do |key, value|
173+
result[key] = 30000000.0 / Float(value)
174+
end
175+
benchmark_run.result = result
176+
benchmark_run.benchmark_result_type = ips_result_type
177+
end
178+
179+
print '.'
180+
begin
181+
BenchmarkRun.import!(benchmark_runs, on_duplicate_key_update: [:result, :benchmark_result_type_id])
182+
rescue ActiveRecord::RecordInvalid => e
183+
puts "#{e.class}: #{e.message}"
184+
end
185+
end
186+
puts
187+
end
188+
end
189+
190+
desc 'Convert vm2 to ips'
191+
task vm2: :environment do
192+
time_result_type = BenchmarkResultType.find_by!(name: 'Execution time', unit: 'Seconds')
193+
ips_result_type = BenchmarkResultType.find_by!(name: 'Iteration per second', unit: 'i/s')
194+
195+
BenchmarkType.all.each do |benchmark_type|
196+
unless benchmark_type.script_url.match(%r[\Ahttps://raw\.githubusercontent\.com/ruby-bench/ruby-bench-suite/master/ruby/benchmark/vm2_.+\.yml\z])
197+
next
198+
end
199+
200+
original_type = BenchmarkType.where.not(id: benchmark_type.id).find_by(category: benchmark_type.category)
201+
if original_type.nil? || !original_type.script_url.match(%r[\Ahttps://raw.githubusercontent.com/ruby-bench/ruby-bench-suite/master/ruby/benchmarks/bm_])
202+
next
203+
end
204+
205+
print "benchmark_type: #{benchmark_type.category}"
206+
original_type.benchmark_runs.where(benchmark_result_type: time_result_type).find_in_batches do |benchmark_runs|
207+
benchmark_runs.each do |benchmark_run|
208+
result = {}
209+
benchmark_run.result.each do |key, value|
210+
result[key] = 6000000.0 / Float(value)
211+
end
212+
benchmark_run.result = result
213+
benchmark_run.benchmark_result_type = ips_result_type
214+
end
215+
216+
print '.'
217+
begin
218+
BenchmarkRun.import!(benchmark_runs, on_duplicate_key_update: [:result, :benchmark_result_type_id])
219+
rescue ActiveRecord::RecordInvalid => e
220+
puts "#{e.class}: #{e.message}"
221+
end
222+
end
223+
puts
224+
end
225+
end
152226
end

0 commit comments

Comments
 (0)