forked from codetriage/CodeTriage
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratch.rb
57 lines (47 loc) · 1.5 KB
/
scratch.rb
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
require"bigdecimal"
defvalues_from_benchmark(file_name)
file_contents=File.read(file_name)
output=[]
file_contents.each_linedo |line|
line =~ /\( +(\d+\.\d+)\)/
begin
output << BigDecimal($1)
rescue=>e
raisee,"Problem with file #{file_name.inspect}:\n#{file_contents}\n#{e.message}"
end
end
output
end
defstudents_t_test(file_1,file_2)
series_1=values_from_benchmark(file_1)
series_2=values_from_benchmark(file_2)
StatisticalTest::TTest.paired_test(0.05,:two_tail,series_1,series_2)
end
branch_names=["tmp/compare_branches/20190610170044486002/master.bench.txt","tmp/compare_branches/20190610170044486002/d9a8778be852b34c4509353352865ade0a6172da.bench.txt"]
series_1=values_from_benchmark(branch_names[0])
series_2=values_from_benchmark(branch_names[1])
require"statistics"
t_test=StatisticalTest::TTest.paired_test(0.05,:two_tail,series_1,series_2)
avg_1=series_1.inject(&:+) / series_1.count
avg_2=series_2.inject(&:+) / series_2.count
faster=avg_2
ifavg_2 < avg_1
winner=branch_names[1]
loser=branch_names[0]
faster=avg_2
slower=avg_1
else
winner=branch_names[0]
loser=branch_names[1]
faster=avg_1
slower=avg_2
end
ratio=slower / faster
ift_test[:alternative]
puts"❤️ " * 40
else
puts"👎 " * 80
end
puts"Branch #{winner.inspect} is faster than #{loser.inspect} by\n#{ratio.to_f}x\n\n"
puts"P-value: #{t_test[:p_value].to_f}"
puts"Is signifigant? (P-value < 0.05): #{t_test[:alternative]}"