-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
659bd79
commit b3e3e12
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rspec-benchmark" | ||
require "tempfile" | ||
|
||
RSpec.describe Slideck::Runner, "#run" do | ||
include RSpec::Benchmark::Matchers | ||
|
||
let(:input) { StringIO.new("".dup, "w+") } | ||
let(:output) { StringIO.new("".dup, "w+") } | ||
let(:env) { {"TTY_TEST" => true} } | ||
|
||
it "runs a presentation with 100 slides at 200 i/s" do | ||
metadata = "align: center\nmargin: 1 2\nsymbols: ascii\n" | ||
slides = Array.new(100) { |i| "---\nSlide#{i}" }.join("\n") | ||
runner = described_class.new(TTY::Screen, input, output, env) | ||
|
||
Tempfile.create("slides.md") do |file| | ||
file << metadata | ||
file << slides | ||
input << "q" | ||
|
||
expect { | ||
file.rewind | ||
input.rewind | ||
runner.run(file.path, color: :always, watch: false) | ||
}.to perform_at_least(200).ips | ||
end | ||
end | ||
|
||
it "runs a presentation with no slides allocating 557 objects" do | ||
runner = described_class.new(TTY::Screen, input, output, env) | ||
file_path = fixtures_path("empty.md") | ||
input << "q" | ||
|
||
expect { | ||
input.rewind | ||
runner.run(file_path, color: :always, watch: false) | ||
}.to perform_allocation(557).objects | ||
end | ||
|
||
it "runs a presentation with 100 slides allocating 2.5K objects" do | ||
metadata = "align: center\nmargin: 1 2\nsymbols: ascii\n" | ||
slides = Array.new(100) { |i| "---\nSlide#{i}" }.join("\n") | ||
runner = described_class.new(TTY::Screen, input, output, env) | ||
|
||
Tempfile.create("slides.md") do |file| | ||
file << metadata | ||
file << slides | ||
input << "q" | ||
|
||
expect { | ||
file.rewind | ||
input.rewind | ||
runner.run(file.path, color: :always, watch: false) | ||
}.to perform_allocation(2555).objects | ||
end | ||
end | ||
|
||
it "runs presentations with increasing slides sizes in linear time" do | ||
sizes = bench_range(8, 10_000) | ||
metadata = "align: center\nmargin: 1 2\nsymbols: ascii\n" | ||
slides = sizes.map { |n| Array.new(n) { |i| "---\nSlide#{i}" }.join("\n") } | ||
runner = described_class.new(TTY::Screen, input, output, env) | ||
|
||
Tempfile.create("slides.md") do |file| | ||
input << "q" | ||
|
||
expect { |_, i| | ||
file.rewind | ||
file << metadata | ||
file << slides[i] | ||
file.rewind | ||
input.rewind | ||
runner.run(file.path, color: :always, watch: false) | ||
}.to perform_linear.in_range(sizes) | ||
end | ||
end | ||
end |