Skip to content

Commit

Permalink
Add performance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jul 20, 2023
1 parent 659bd79 commit b3e3e12
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4.0")
gem "listen", "3.0.8"
end

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1.0")
gem "rspec-benchmark", "~> 0.6"
end

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
gem "coveralls_reborn", "~> 0.24.0"
gem "simplecov", "~> 0.21.0"
Expand Down
79 changes: 79 additions & 0 deletions spec/perf/runner_spec.rb
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

0 comments on commit b3e3e12

Please sign in to comment.