File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ def before_test
2424 build
2525end
2626
27+ def benchmark
28+ build
29+ system ( "sus --verbose benchmark" )
30+ end
31+
2732# Update the project documentation with the new version number.
2833#
2934# @parameter version [String] The new version number.
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ # Released under the MIT License.
4+ # Copyright, 2026, by Samuel Williams.
5+
6+ require_relative "../config/environment"
7+
8+ require "coverage"
9+ require "sus/fixtures/benchmark"
10+ require "tmpdir"
11+
12+ require "ruby/coverage"
13+
14+ describe Ruby ::Coverage ::Tracer do
15+ include Sus ::Fixtures ::Benchmark
16+
17+ SAMPLES = 8
18+
19+ def around
20+ Dir . mktmpdir do |root |
21+ @path = File . join ( root , "workload.rb" )
22+
23+ File . write ( @path , <<~RUBY )
24+ i = 0
25+ total = 0
26+ while i < 1_000_000
27+ total += i
28+ i += 1
29+ end
30+ total
31+ RUBY
32+
33+ yield
34+ end
35+ end
36+
37+ attr :path
38+
39+ def stop_standard_coverage
40+ if ::Coverage . running?
41+ ::Coverage . result ( stop : true , clear : true )
42+ end
43+ end
44+
45+ measure "load without coverage" do |repeats |
46+ repeats . exactly ( SAMPLES ) . times do
47+ load ( self . path )
48+ end
49+ end
50+
51+ measure "load with stdlib coverage" do |repeats |
52+ repeats . exactly ( SAMPLES ) . times do
53+ begin
54+ ::Coverage . start ( lines : true )
55+ load ( self . path )
56+ ensure
57+ stop_standard_coverage
58+ end
59+ end
60+ end
61+
62+ measure "load with ruby coverage" do |repeats |
63+ repeats . exactly ( SAMPLES ) . times do
64+ tracer = Ruby ::Coverage ::Tracer . new do |_path , iseq |
65+ counts = [ ]
66+
67+ Ruby ::Coverage . executable_lines ( iseq ) . each do |line |
68+ counts [ line ] = 0
69+ end
70+
71+ counts
72+ end
73+
74+ begin
75+ tracer . start
76+ load ( self . path )
77+ ensure
78+ tracer . stop
79+ end
80+ end
81+ end
82+ end
Original file line number Diff line number Diff line change 2121
2222group :test do
2323 gem "sus"
24+ gem "sus-fixtures-benchmark"
2425 gem "covered"
2526
2627 gem "rubocop"
You can’t perform that action at this time.
0 commit comments