debian-mirror-gitlab/derailed-benchmarks/test/derailed_benchmarks/stats_from_dir_test.rb

126 lines
3.6 KiB
Ruby
Raw Normal View History

2019-10-03 14:02:42 +05:30
# frozen_string_literal: true
require 'test_helper'
class StatsFromDirTest < ActiveSupport::TestCase
test "that it works" do
dir = fixtures_dir("stats/significant")
branch_info = {}
branch_info["loser"] = { desc: "Old commit", time: Time.now, file: dir.join("loser.bench.txt"), name: "loser" }
branch_info["winner"] = { desc: "I am the new commit", time: Time.now + 1, file: dir.join("winner.bench.txt"), name: "winner" }
stats = DerailedBenchmarks::StatsFromDir.new(branch_info).call
newest = stats.newest
oldest = stats.oldest
assert newest.average < oldest.average
assert_equal "winner", newest.name
assert_equal "loser", oldest.name
2019-10-07 21:24:36 +05:30
assert_in_delta 0.26, stats.d_max, 0.01
2020-01-01 13:55:28 +05:30
assert_in_delta 0.2145966026289347, stats.d_critical, 0.00001
2019-10-03 14:02:42 +05:30
assert_equal true, stats.significant?
2019-12-20 00:11:08 +05:30
format = DerailedBenchmarks::StatsFromDir::FORMAT
assert_equal "1.0062", format % stats.x_faster
assert_equal "0.6147", format % stats.percent_faster
assert_equal "11.3844", format % newest.median
2020-01-01 13:55:28 +05:30
end
test "alignment" do
dir = fixtures_dir("stats/significant")
branch_info = {}
branch_info["loser"] = { desc: "Old commit", time: Time.now, file: dir.join("loser.bench.txt"), name: "loser" }
branch_info["winner"] = { desc: "I am the new commit", time: Time.now + 1, file: dir.join("winner.bench.txt"), name: "winner" }
stats = DerailedBenchmarks::StatsFromDir.new(branch_info).call
def stats.percent_faster
-0.1
end
def stats.x_faster
0.9922
end
assert_equal 1, stats.align.length
end
2019-10-03 14:02:42 +05:30
test "banner faster" do
dir = fixtures_dir("stats/significant")
branch_info = {}
branch_info["loser"] = { desc: "Old commit", time: Time.now, file: dir.join("loser.bench.txt"), name: "loser" }
branch_info["winner"] = { desc: "I am the new commit", time: Time.now + 1, file: dir.join("winner.bench.txt"), name: "winner" }
stats = DerailedBenchmarks::StatsFromDir.new(branch_info).call
newest = stats.newest
oldest = stats.oldest
# Test fixture for banner
2019-10-07 21:24:36 +05:30
def stats.d_max
"0.037"
end
def stats.d_critical
"0.001"
2019-10-03 14:02:42 +05:30
end
2019-12-20 00:11:08 +05:30
def newest.median
2019-10-03 14:02:42 +05:30
10.5
end
2019-12-20 00:11:08 +05:30
def oldest.median
2019-10-03 14:02:42 +05:30
11.0
end
2019-12-20 00:11:08 +05:30
expected = <<~EOM
2019-10-03 14:02:42 +05:30
[winner] "I am the new commit" - (10.5 seconds)
2019-12-20 00:11:08 +05:30
FASTER 🚀🚀🚀 by:
2019-10-03 14:02:42 +05:30
1.0476x [older/newer]
4.5455% [(older - newer) / older * 100]
[loser] "Old commit" - (11.0 seconds)
EOM
actual = StringIO.new
stats.banner(actual)
assert_match expected, actual.string
end
test "banner slower" do
dir = fixtures_dir("stats/significant")
branch_info = {}
branch_info["loser"] = { desc: "I am the new commit", time: Time.now, file: dir.join("loser.bench.txt"), name: "loser" }
branch_info["winner"] = { desc: "Old commit", time: Time.now - 10, file: dir.join("winner.bench.txt"), name: "winner" }
stats = DerailedBenchmarks::StatsFromDir.new(branch_info).call
newest = stats.newest
oldest = stats.oldest
2019-12-20 00:11:08 +05:30
def oldest.median
2019-10-03 14:02:42 +05:30
10.5
end
2019-12-20 00:11:08 +05:30
def newest.median
2019-10-03 14:02:42 +05:30
11.0
end
2019-12-20 00:11:08 +05:30
expected = <<~EOM
2019-10-03 14:02:42 +05:30
[loser] "I am the new commit" - (11.0 seconds)
2019-12-20 00:11:08 +05:30
SLOWER 🐢🐢🐢 by:
0.9545x [older/newer]
2019-10-03 14:02:42 +05:30
-4.7619% [(older - newer) / older * 100]
[winner] "Old commit" - (10.5 seconds)
EOM
actual = StringIO.new
stats.banner(actual)
assert_match expected, actual.string
end
test "stats from samples with slightly different sizes" do
stats = DerailedBenchmarks::StatsFromDir.new({})
2019-10-07 21:24:36 +05:30
out = stats.statistical_test([100,101,102, 100, 101, 99], [1,3, 3, 2])
2019-10-03 14:02:42 +05:30
assert out[:alternative]
end
end